blob: fa2c01034b3bc5b26982d32af0759745a9c4a27e [file] [log] [blame]
Brad Bishop977dc1a2019-02-06 16:01:43 -05001From c3a7da1bbb6d2df8ab7ea1c7ce34ded37a21959f Mon Sep 17 00:00:00 2001
2From: Yu Watanabe <watanabe.yu+github@gmail.com>
3Date: Fri, 10 Aug 2018 11:07:54 +0900
4Subject: [PATCH] journal: do not remove multiple spaces after identifier in
5 syslog message
6
7Single space is used as separator.
8C.f. discussions in #156.
9
10Fixes #9839 introduced by a6aadf4ae0bae185dc4c414d492a4a781c80ffe5.
11
12Patch backported from systemd master at
138595102d3ddde6d25c282f965573a6de34ab4421.
14
15This matches the change done for systemd-journald, hence forming the second
16part of the fix for CVE-2018-16866
17---
18 src/journal/journald-syslog.c | 4 +++-
19 src/journal/test-journal-syslog.c | 24 ++++++++++++++----------
20 2 files changed, 17 insertions(+), 11 deletions(-)
21
22diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
23index 97711ac7a3..e0b55cc566 100644
24--- a/src/journal/journald-syslog.c
25+++ b/src/journal/journald-syslog.c
26@@ -219,7 +219,9 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid)
27 if (t)
28 *identifier = t;
29
30- e += strspn(p + e, WHITESPACE);
31+ /* Single space is used as separator */
32+ if (p[e] != '\0' && strchr(WHITESPACE, p[e]))
33+ e++;
34
35 *buf = p + e;
36 return e;
37diff --git a/src/journal/test-journal-syslog.c b/src/journal/test-journal-syslog.c
38index 05f759817e..7294cde032 100644
39--- a/src/journal/test-journal-syslog.c
40+++ b/src/journal/test-journal-syslog.c
41@@ -6,7 +6,7 @@
42 #include "string-util.h"
43
44 static void test_syslog_parse_identifier(const char *str,
45- const char *ident, const char *pid, int ret) {
46+ const char *ident, const char *pid, const char *rest, int ret) {
47 const char *buf = str;
48 _cleanup_free_ char *ident2 = NULL, *pid2 = NULL;
49 int ret2;
50@@ -16,18 +16,22 @@ static void test_syslog_parse_identifier(const char *str,
51 assert_se(ret == ret2);
52 assert_se(ident == ident2 || streq_ptr(ident, ident2));
53 assert_se(pid == pid2 || streq_ptr(pid, pid2));
54+ assert_se(streq(buf, rest));
55 }
56
57 int main(void) {
58- test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", 11);
59- test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, 6);
60- test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, 7);
61- test_syslog_parse_identifier("pidu xxx", NULL, NULL, 0);
62- test_syslog_parse_identifier(":", "", NULL, 1);
63- test_syslog_parse_identifier(": ", "", NULL, 3);
64- test_syslog_parse_identifier("pidu:", "pidu", NULL, 5);
65- test_syslog_parse_identifier("pidu: ", "pidu", NULL, 6);
66- test_syslog_parse_identifier("pidu : ", NULL, NULL, 0);
67+ test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", "xxx", 11);
68+ test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, "xxx", 6);
69+ test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, " xxx", 6);
70+ test_syslog_parse_identifier("pidu xxx", NULL, NULL, "pidu xxx", 0);
71+ test_syslog_parse_identifier(" pidu xxx", NULL, NULL, " pidu xxx", 0);
72+ test_syslog_parse_identifier("", NULL, NULL, "", 0);
73+ test_syslog_parse_identifier(" ", NULL, NULL, " ", 0);
74+ test_syslog_parse_identifier(":", "", NULL, "", 1);
75+ test_syslog_parse_identifier(": ", "", NULL, " ", 2);
76+ test_syslog_parse_identifier("pidu:", "pidu", NULL, "", 5);
77+ test_syslog_parse_identifier("pidu: ", "pidu", NULL, "", 6);
78+ test_syslog_parse_identifier("pidu : ", NULL, NULL, "pidu : ", 0);
79
80 return 0;
81 }
82--
832.11.0
84