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