valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

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

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