naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
4fbe94
From fffbf1f90be5236b310bc0b10034815b1051f0ac Mon Sep 17 00:00:00 2001
4fbe94
From: Yu Watanabe <watanabe.yu+github@gmail.com>
4fbe94
Date: Fri, 10 Aug 2018 11:07:54 +0900
4fbe94
Subject: [PATCH] journal: do not remove multiple spaces after identifier in
4fbe94
 syslog message
4fbe94
4fbe94
Single space is used as separator.
4fbe94
C.f. discussions in #156.
4fbe94
4fbe94
Fixes #9839 introduced by a6aadf4ae0bae185dc4c414d492a4a781c80ffe5.
4fbe94
4fbe94
(cherry picked from commit 8595102d3ddde6d25c282f965573a6de34ab4421)
4fbe94
4fbe94
Resolves: #1691817
4fbe94
---
4fbe94
 src/journal/journald-syslog.c     |  4 +++-
4fbe94
 src/journal/test-journal-syslog.c | 24 ++++++++++++++----------
4fbe94
 2 files changed, 17 insertions(+), 11 deletions(-)
4fbe94
4fbe94
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
4fbe94
index 97711ac7a3..e0b55cc566 100644
4fbe94
--- a/src/journal/journald-syslog.c
4fbe94
+++ b/src/journal/journald-syslog.c
4fbe94
@@ -219,7 +219,9 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid)
4fbe94
         if (t)
4fbe94
                 *identifier = t;
4fbe94
 
4fbe94
-        e += strspn(p + e, WHITESPACE);
4fbe94
+        /* Single space is used as separator */
4fbe94
+        if (p[e] != '\0' && strchr(WHITESPACE, p[e]))
4fbe94
+                e++;
4fbe94
 
4fbe94
         *buf = p + e;
4fbe94
         return e;
4fbe94
diff --git a/src/journal/test-journal-syslog.c b/src/journal/test-journal-syslog.c
4fbe94
index 05f759817e..7294cde032 100644
4fbe94
--- a/src/journal/test-journal-syslog.c
4fbe94
+++ b/src/journal/test-journal-syslog.c
4fbe94
@@ -6,7 +6,7 @@
4fbe94
 #include "string-util.h"
4fbe94
 
4fbe94
 static void test_syslog_parse_identifier(const char *str,
4fbe94
-                                         const char *ident, const char *pid, int ret) {
4fbe94
+                                         const char *ident, const char *pid, const char *rest, int ret) {
4fbe94
         const char *buf = str;
4fbe94
         _cleanup_free_ char *ident2 = NULL, *pid2 = NULL;
4fbe94
         int ret2;
4fbe94
@@ -16,18 +16,22 @@ static void test_syslog_parse_identifier(const char *str,
4fbe94
         assert_se(ret == ret2);
4fbe94
         assert_se(ident == ident2 || streq_ptr(ident, ident2));
4fbe94
         assert_se(pid == pid2 || streq_ptr(pid, pid2));
4fbe94
+        assert_se(streq(buf, rest));
4fbe94
 }
4fbe94
 
4fbe94
 int main(void) {
4fbe94
-        test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", 11);
4fbe94
-        test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, 6);
4fbe94
-        test_syslog_parse_identifier("pidu:  xxx", "pidu", NULL, 7);
4fbe94
-        test_syslog_parse_identifier("pidu xxx", NULL, NULL, 0);
4fbe94
-        test_syslog_parse_identifier(":", "", NULL, 1);
4fbe94
-        test_syslog_parse_identifier(":  ", "", NULL, 3);
4fbe94
-        test_syslog_parse_identifier("pidu:", "pidu", NULL, 5);
4fbe94
-        test_syslog_parse_identifier("pidu: ", "pidu", NULL, 6);
4fbe94
-        test_syslog_parse_identifier("pidu : ", NULL, NULL, 0);
4fbe94
+        test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", "xxx", 11);
4fbe94
+        test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, "xxx", 6);
4fbe94
+        test_syslog_parse_identifier("pidu:  xxx", "pidu", NULL, " xxx", 6);
4fbe94
+        test_syslog_parse_identifier("pidu xxx", NULL, NULL, "pidu xxx", 0);
4fbe94
+        test_syslog_parse_identifier("   pidu xxx", NULL, NULL, "   pidu xxx", 0);
4fbe94
+        test_syslog_parse_identifier("", NULL, NULL, "", 0);
4fbe94
+        test_syslog_parse_identifier("  ", NULL, NULL, "  ", 0);
4fbe94
+        test_syslog_parse_identifier(":", "", NULL, "", 1);
4fbe94
+        test_syslog_parse_identifier(":  ", "", NULL, " ", 2);
4fbe94
+        test_syslog_parse_identifier("pidu:", "pidu", NULL, "", 5);
4fbe94
+        test_syslog_parse_identifier("pidu: ", "pidu", NULL, "", 6);
4fbe94
+        test_syslog_parse_identifier("pidu : ", NULL, NULL, "pidu : ", 0);
4fbe94
 
4fbe94
         return 0;
4fbe94
 }