summaryrefslogtreecommitdiff
path: root/src/journal/sd-journal.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-07-13 00:10:37 +0200
committerLennart Poettering <lennart@poettering.net>2012-07-13 00:32:32 +0200
commit362a3f8122e070589a4d61f7752b990090c75432 (patch)
tree89a5680f434fa62168a0ff95d2b53e2b8c556573 /src/journal/sd-journal.c
parent91a31dde6e92c0d4c42abadf970083f6faba87ec (diff)
journal: check fields we search for more carefully
Diffstat (limited to 'src/journal/sd-journal.c')
-rw-r--r--src/journal/sd-journal.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index b6e74a0d4c..f4ef1aea7c 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -1426,6 +1426,34 @@ _public_ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id12
return 0;
}
+static bool field_is_valid(const char *field) {
+ const char *p;
+
+ assert(field);
+
+ if (isempty(field))
+ return false;
+
+ if (startswith(field, "__"))
+ return false;
+
+ for (p = field; *p; p++) {
+
+ if (*p == '_')
+ continue;
+
+ if (*p >= 'A' && *p <= 'Z')
+ continue;
+
+ if (*p >= '0' && *p <= '9')
+ continue;
+
+ return false;
+ }
+
+ return true;
+}
+
_public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **data, size_t *size) {
JournalFile *f;
uint64_t i, n;
@@ -1442,7 +1470,7 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
if (!size)
return -EINVAL;
- if (isempty(field) || strchr(field, '='))
+ if (!field_is_valid(field))
return -EINVAL;
f = j->current_file;