journald: take leading spaces into account in syslog_parse_identifier
authorEvgeny Vereshchagin <evvers@ya.ru>
Fri, 10 Aug 2018 12:55:09 +0000 (12:55 +0000)
committerEvgeny Vereshchagin <evvers@ya.ru>
Fri, 10 Aug 2018 13:35:06 +0000 (13:35 +0000)
This is a kind of follow-up to e88baee88fad8bc59d3 which should finally fix
the issue which that commit was supposed to fix.

src/journal/journald-syslog.c
src/journal/test-journal-syslog.c

index 6dc6b07..72b73c2 100644 (file)
@@ -222,8 +222,9 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid)
         if (p[e] != '\0' && strchr(WHITESPACE, p[e]))
                 e++;
 
+        l = (p - *buf) + e;
         *buf = p + e;
-        return e;
+        return l;
 }
 
 static int syslog_skip_timestamp(const char **buf) {
index 120477c..415b9d2 100644 (file)
@@ -41,6 +41,8 @@ int main(void) {
         test_syslog_parse_identifier("  ", NULL, NULL, "  ", 0);
         test_syslog_parse_identifier(":", "", NULL, "", 1);
         test_syslog_parse_identifier(":  ", "", NULL, " ", 2);
+        test_syslog_parse_identifier(" :", "", NULL, "", 2);
+        test_syslog_parse_identifier("   pidu:", "pidu", NULL, "", 8);
         test_syslog_parse_identifier("pidu:", "pidu", NULL, "", 5);
         test_syslog_parse_identifier("pidu: ", "pidu", NULL, "", 6);
         test_syslog_parse_identifier("pidu : ", NULL, NULL, "pidu : ", 0);