valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0183-sd-journal-escape-binary-data-in-match_make_string.patch

ff6046
From b234013c618e3a346fd831d65e08662844fc9f81 Mon Sep 17 00:00:00 2001
ff6046
From: Evgeny Vereshchagin <evvers@ya.ru>
ff6046
Date: Fri, 12 Oct 2018 12:17:04 +0000
ff6046
Subject: [PATCH] sd-journal: escape binary data in match_make_string()
ff6046
ff6046
Fixes: #10383
ff6046
(cherry picked from commit 9e8b1ec08e8eb0b4611b7caf6adb8828feb32312)
ff6046
ff6046
Resolves: #1683319
ff6046
---
ff6046
 src/journal/sd-journal.c         | 3 ++-
ff6046
 src/journal/test-journal-match.c | 4 +++-
ff6046
 2 files changed, 5 insertions(+), 2 deletions(-)
ff6046
ff6046
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
ff6046
index 83abd82d1c..323300baec 100644
ff6046
--- a/src/journal/sd-journal.c
ff6046
+++ b/src/journal/sd-journal.c
ff6046
@@ -16,6 +16,7 @@
ff6046
 #include "catalog.h"
ff6046
 #include "compress.h"
ff6046
 #include "dirent-util.h"
ff6046
+#include "escape.h"
ff6046
 #include "fd-util.h"
ff6046
 #include "fileio.h"
ff6046
 #include "format-util.h"
ff6046
@@ -381,7 +382,7 @@ static char *match_make_string(Match *m) {
ff6046
                 return strdup("none");
ff6046
 
ff6046
         if (m->type == MATCH_DISCRETE)
ff6046
-                return strndup(m->data, m->size);
ff6046
+                return cescape_length(m->data, m->size);
ff6046
 
ff6046
         LIST_FOREACH(matches, i, m->matches) {
ff6046
                 char *t, *k;
ff6046
diff --git a/src/journal/test-journal-match.c b/src/journal/test-journal-match.c
ff6046
index 4e5ad1791a..d2a52b9145 100644
ff6046
--- a/src/journal/test-journal-match.c
ff6046
+++ b/src/journal/test-journal-match.c
ff6046
@@ -23,6 +23,8 @@ int main(int argc, char *argv[]) {
ff6046
         assert_se(sd_journal_add_match(j, "", 0) < 0);
ff6046
         assert_se(sd_journal_add_match(j, "=", 0) < 0);
ff6046
         assert_se(sd_journal_add_match(j, "=xxxxx", 0) < 0);
ff6046
+        assert_se(sd_journal_add_match(j, (uint8_t[4]){'A', '=', '\1', '\2'}, 4) >= 0);
ff6046
+        assert_se(sd_journal_add_match(j, (uint8_t[5]){'B', '=', 'C', '\0', 'D'}, 5) >= 0);
ff6046
         assert_se(sd_journal_add_match(j, "HALLO=WALDO", 0) >= 0);
ff6046
         assert_se(sd_journal_add_match(j, "QUUX=mmmm", 0) >= 0);
ff6046
         assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0);
ff6046
@@ -53,7 +55,7 @@ int main(int argc, char *argv[]) {
ff6046
 
ff6046
         printf("resulting match expression is: %s\n", t);
ff6046
 
ff6046
-        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))))"));
ff6046
+        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)))"));
ff6046
 
ff6046
         return 0;
ff6046
 }