diff options
-rw-r--r-- | src/journal/journald-native.c | 40 | ||||
-rw-r--r-- | src/shared/journal-util.c | 38 | ||||
-rw-r--r-- | src/shared/journal-util.h | 3 |
3 files changed, 44 insertions, 37 deletions
diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c index 1ff4e29849..0953324cc6 100644 --- a/src/journal/journald-native.c +++ b/src/journal/journald-native.c @@ -28,6 +28,7 @@ #include "fs-util.h" #include "io-util.h" #include "journal-importer.h" +#include "journal-util.h" #include "journald-console.h" #include "journald-kmsg.h" #include "journald-native.h" @@ -43,41 +44,6 @@ #include "string-util.h" #include "unaligned.h" -bool valid_user_field(const char *p, size_t l, bool allow_protected) { - const char *a; - - /* We kinda enforce POSIX syntax recommendations for - environment variables here, but make a couple of additional - requirements. - - http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html */ - - /* No empty field names */ - if (l <= 0) - return false; - - /* Don't allow names longer than 64 chars */ - if (l > 64) - return false; - - /* Variables starting with an underscore are protected */ - if (!allow_protected && p[0] == '_') - return false; - - /* Don't allow digits as first character */ - if (p[0] >= '0' && p[0] <= '9') - return false; - - /* Only allow A-Z0-9 and '_' */ - for (a = p; a < p + l; a++) - if ((*a < 'A' || *a > 'Z') && - (*a < '0' || *a > '9') && - *a != '_') - return false; - - return true; -} - static bool allow_object_pid(const struct ucred *ucred) { return ucred && ucred->uid == 0; } @@ -201,7 +167,7 @@ static int server_process_entry( q = memchr(p, '=', e - p); if (q) { - if (valid_user_field(p, q - p, false)) { + if (journal_field_valid(p, q - p, false)) { size_t l; l = e - p; @@ -257,7 +223,7 @@ static int server_process_entry( k[e - p] = '='; memcpy(k + (e - p) + 1, e + 1 + sizeof(uint64_t), l); - if (valid_user_field(p, e - p, false)) { + if (journal_field_valid(p, e - p, false)) { iovec[n].iov_base = k; iovec[n].iov_len = (e - p) + 1 + l; entry_size += iovec[n].iov_len; diff --git a/src/shared/journal-util.c b/src/shared/journal-util.c index fff3dfc9d1..82f193ffd8 100644 --- a/src/shared/journal-util.c +++ b/src/shared/journal-util.c @@ -149,3 +149,41 @@ int journal_access_check_and_warn(sd_journal *j, bool quiet) { return r; } + +bool journal_field_valid(const char *p, size_t l, bool allow_protected) { + const char *a; + + /* We kinda enforce POSIX syntax recommendations for + environment variables here, but make a couple of additional + requirements. + + http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html */ + + if (l == (size_t) -1) + l = strlen(p); + + /* No empty field names */ + if (l <= 0) + return false; + + /* Don't allow names longer than 64 chars */ + if (l > 64) + return false; + + /* Variables starting with an underscore are protected */ + if (!allow_protected && p[0] == '_') + return false; + + /* Don't allow digits as first character */ + if (p[0] >= '0' && p[0] <= '9') + return false; + + /* Only allow A-Z0-9 and '_' */ + for (a = p; a < p + l; a++) + if ((*a < 'A' || *a > 'Z') && + (*a < '0' || *a > '9') && + *a != '_') + return false; + + return true; +} diff --git a/src/shared/journal-util.h b/src/shared/journal-util.h index 499e6c62ec..95613bba10 100644 --- a/src/shared/journal-util.h +++ b/src/shared/journal-util.h @@ -19,7 +19,10 @@ ***/ #include <stdbool.h> +#include <sys/types.h> #include "sd-journal.h" +bool journal_field_valid(const char *p, size_t l, bool allow_protected); + int journal_access_check_and_warn(sd_journal *j, bool quiet); |