ryantimwilson / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
c62b8e
From abb072100e72c07c5cf98b02f5b1a15a48f4b496 Mon Sep 17 00:00:00 2001
c62b8e
From: Yu Watanabe <watanabe.yu+github@gmail.com>
c62b8e
Date: Fri, 4 Jan 2019 15:33:43 +0100
c62b8e
Subject: [PATCH] journal: fix syslog_parse_identifier()
c62b8e
c62b8e
Fixes #9829.
c62b8e
c62b8e
(cherry-picked from commit a6aadf4ae0bae185dc4c414d492a4a781c80ffe5)
c62b8e
c62b8e
Resolves: #1657794
c62b8e
c62b8e
[msekleta: Fix for CVE-2018-16866]
c62b8e
---
c62b8e
 src/journal/journald-syslog.c     | 6 +++---
c62b8e
 src/journal/test-journal-syslog.c | 8 +++++++-
c62b8e
 2 files changed, 10 insertions(+), 4 deletions(-)
c62b8e
c62b8e
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
c62b8e
index 01d2bf69f4..3ea5d79c3a 100644
c62b8e
--- a/src/journal/journald-syslog.c
c62b8e
+++ b/src/journal/journald-syslog.c
c62b8e
@@ -209,7 +209,7 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid)
c62b8e
         e = l;
c62b8e
         l--;
c62b8e
 
c62b8e
-        if (p[l-1] == ']') {
c62b8e
+        if (l > 0 && p[l-1] == ']') {
c62b8e
                 size_t k = l-1;
c62b8e
 
c62b8e
                 for (;;) {
c62b8e
@@ -234,8 +234,8 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid)
c62b8e
         if (t)
c62b8e
                 *identifier = t;
c62b8e
 
c62b8e
-        if (strchr(WHITESPACE, p[e]))
c62b8e
-                e++;
c62b8e
+        e += strspn(p + e, WHITESPACE);
c62b8e
+
c62b8e
         *buf = p + e;
c62b8e
         return e;
c62b8e
 }
c62b8e
diff --git a/src/journal/test-journal-syslog.c b/src/journal/test-journal-syslog.c
c62b8e
index c99ca0654b..f56a813774 100644
c62b8e
--- a/src/journal/test-journal-syslog.c
c62b8e
+++ b/src/journal/test-journal-syslog.c
c62b8e
@@ -22,7 +22,7 @@
c62b8e
 #include "journald-syslog.h"
c62b8e
 #include "macro.h"
c62b8e
 
c62b8e
-static void test_syslog_parse_identifier(const char* str,
c62b8e
+static void test_syslog_parse_identifier(const char *str,
c62b8e
                                          const char *ident, const char*pid, int ret) {
c62b8e
         const char *buf = str;
c62b8e
         _cleanup_free_ char *ident2 = NULL, *pid2 = NULL;
c62b8e
@@ -38,7 +38,13 @@ static void test_syslog_parse_identifier(const char* str,
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
 
c62b8e
         return 0;
c62b8e
 }