Blame SOURCES/0079-journal-fix-syslog_parse_identifier.patch

a3e2b5
From d355618518f26bd045df81a52dade79ac3079f3f Mon Sep 17 00:00:00 2001
a3e2b5
From: Yu Watanabe <watanabe.yu+github@gmail.com>
a3e2b5
Date: Wed, 8 Aug 2018 15:06:36 +0900
a3e2b5
Subject: [PATCH] journal: fix syslog_parse_identifier()
a3e2b5
a3e2b5
Fixes #9829.
a3e2b5
a3e2b5
(cherry-picked from commit a6aadf4ae0bae185dc4c414d492a4a781c80ffe5)
a3e2b5
a3e2b5
Resolves: #1664978
a3e2b5
---
a3e2b5
 src/journal/journald-syslog.c     |  6 +++---
a3e2b5
 src/journal/test-journal-syslog.c | 10 ++++++++--
a3e2b5
 2 files changed, 11 insertions(+), 5 deletions(-)
a3e2b5
a3e2b5
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
a3e2b5
index 9dea116722..97711ac7a3 100644
a3e2b5
--- a/src/journal/journald-syslog.c
a3e2b5
+++ b/src/journal/journald-syslog.c
a3e2b5
@@ -194,7 +194,7 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid)
a3e2b5
         e = l;
a3e2b5
         l--;
a3e2b5
 
a3e2b5
-        if (p[l-1] == ']') {
a3e2b5
+        if (l > 0 && p[l-1] == ']') {
a3e2b5
                 size_t k = l-1;
a3e2b5
 
a3e2b5
                 for (;;) {
a3e2b5
@@ -219,8 +219,8 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid)
a3e2b5
         if (t)
a3e2b5
                 *identifier = t;
a3e2b5
 
a3e2b5
-        if (strchr(WHITESPACE, p[e]))
a3e2b5
-                e++;
a3e2b5
+        e += strspn(p + e, WHITESPACE);
a3e2b5
+
a3e2b5
         *buf = p + e;
a3e2b5
         return e;
a3e2b5
 }
a3e2b5
diff --git a/src/journal/test-journal-syslog.c b/src/journal/test-journal-syslog.c
a3e2b5
index 9ba86f6c8a..05f759817e 100644
a3e2b5
--- a/src/journal/test-journal-syslog.c
a3e2b5
+++ b/src/journal/test-journal-syslog.c
a3e2b5
@@ -5,8 +5,8 @@
a3e2b5
 #include "macro.h"
a3e2b5
 #include "string-util.h"
a3e2b5
 
a3e2b5
-static void test_syslog_parse_identifier(const char* str,
a3e2b5
-                                         const char *ident, const char*pid, int ret) {
a3e2b5
+static void test_syslog_parse_identifier(const char *str,
a3e2b5
+                                         const char *ident, const char *pid, int ret) {
a3e2b5
         const char *buf = str;
a3e2b5
         _cleanup_free_ char *ident2 = NULL, *pid2 = NULL;
a3e2b5
         int ret2;
a3e2b5
@@ -21,7 +21,13 @@ static void test_syslog_parse_identifier(const char* str,
a3e2b5
 int main(void) {
a3e2b5
         test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", 11);
a3e2b5
         test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, 6);
a3e2b5
+        test_syslog_parse_identifier("pidu:  xxx", "pidu", NULL, 7);
a3e2b5
         test_syslog_parse_identifier("pidu xxx", NULL, NULL, 0);
a3e2b5
+        test_syslog_parse_identifier(":", "", NULL, 1);
a3e2b5
+        test_syslog_parse_identifier(":  ", "", NULL, 3);
a3e2b5
+        test_syslog_parse_identifier("pidu:", "pidu", NULL, 5);
a3e2b5
+        test_syslog_parse_identifier("pidu: ", "pidu", NULL, 6);
a3e2b5
+        test_syslog_parse_identifier("pidu : ", NULL, NULL, 0);
a3e2b5
 
a3e2b5
         return 0;
a3e2b5
 }