ryantimwilson / rpms / systemd

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