]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-journal: escape binary data in match_make_string()
authorEvgeny Vereshchagin <evvers@ya.ru>
Fri, 12 Oct 2018 12:17:04 +0000 (12:17 +0000)
committerLennart Poettering <lennart@poettering.net>
Tue, 23 Oct 2018 17:33:01 +0000 (19:33 +0200)
Fixes: #10383
src/journal/sd-journal.c
src/journal/test-journal-match.c

index 023395d8de3a55b117dac839af9696d1d9040d16..b54e8020f1de036cd5139d901344604c7601621c 100644 (file)
@@ -16,6 +16,7 @@
 #include "catalog.h"
 #include "compress.h"
 #include "dirent-util.h"
+#include "escape.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "format-util.h"
@@ -381,7 +382,7 @@ static char *match_make_string(Match *m) {
                 return strdup("none");
 
         if (m->type == MATCH_DISCRETE)
-                return strndup(m->data, m->size);
+                return cescape_length(m->data, m->size);
 
         LIST_FOREACH(matches, i, m->matches) {
                 char *t, *k;
index ba415fcc38375bff949eeaa4121af234fadec83b..897364201cfde36dd24e3c0341bf103ea4590c70 100644 (file)
@@ -24,6 +24,8 @@ int main(int argc, char *argv[]) {
         assert_se(sd_journal_add_match(j, "", 0) < 0);
         assert_se(sd_journal_add_match(j, "=", 0) < 0);
         assert_se(sd_journal_add_match(j, "=xxxxx", 0) < 0);
+        assert_se(sd_journal_add_match(j, (uint8_t[4]){'A', '=', '\1', '\2'}, 4) >= 0);
+        assert_se(sd_journal_add_match(j, (uint8_t[5]){'B', '=', 'C', '\0', 'D'}, 5) >= 0);
         assert_se(sd_journal_add_match(j, "HALLO=WALDO", 0) >= 0);
         assert_se(sd_journal_add_match(j, "QUUX=mmmm", 0) >= 0);
         assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0);
@@ -54,7 +56,7 @@ int main(int argc, char *argv[]) {
 
         printf("resulting match expression is: %s\n", t);
 
-        assert_se(streq(t, "(((L3=ok OR L3=yes) OR ((L4_2=ok OR L4_2=yes) AND (L4_1=ok OR L4_1=yes))) AND ((TWO=two AND (ONE=two OR ONE=one)) OR (PIFF=paff AND (QUUX=yyyyy OR QUUX=xxxxx OR QUUX=mmmm) AND (HALLO= OR HALLO=WALDO))))"));
+        assert_se(streq(t, "(((L3=ok OR L3=yes) OR ((L4_2=ok OR L4_2=yes) AND (L4_1=ok OR L4_1=yes))) AND ((TWO=two AND (ONE=two OR ONE=one)) OR (PIFF=paff AND (QUUX=yyyyy OR QUUX=xxxxx OR QUUX=mmmm) AND (HALLO= OR HALLO=WALDO) AND B=C\\000D AND A=\\001\\002)))"));
 
         return 0;
 }