anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0203-journal-do-not-remove-multiple-spaces-after-identifi.patch

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