From 1e0c5fc2a76e4f3d508331f410899c50493e1fc9 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Fri, 10 Aug 2018 12:45:42 +0000 Subject: [PATCH 1/3] journald: make it clear that dev_kmsg_record modifies the string passed to it The function replaces a couple commas, a semicolon and the final newline with zero bytes in the string passed to it. The 'const' seems to have been added by accident during a bulk edit (more specifically 3b3154df7e2773332bb814). --- src/journal/journald-kmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index e9aff13168..7ad673362a 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -93,7 +93,7 @@ static bool is_us(const char *identifier, const char *pid) { streq(identifier, program_invocation_short_name); } -static void dev_kmsg_record(Server *s, const char *p, size_t l) { +static void dev_kmsg_record(Server *s, char *p, size_t l) { _cleanup_free_ char *message = NULL, *syslog_priority = NULL, *syslog_pid = NULL, *syslog_facility = NULL, *syslog_identifier = NULL, *source_time = NULL, *identifier = NULL, *pid = NULL; struct iovec iovec[N_IOVEC_META_FIELDS + 7 + N_IOVEC_KERNEL_FIELDS + 2 + N_IOVEC_UDEV_FIELDS]; From 30eddcd51b8a472e05d3b8d1f0b89fbd3e094d71 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Fri, 10 Aug 2018 12:52:07 +0000 Subject: [PATCH 2/3] journald: free the allocated memory before returning from dev_kmsg_record This fixes a minor memory leak. --- src/journal/journald-kmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index 7ad673362a..7644bebfc8 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -191,7 +191,7 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) { e = memchr(k, '\n', l); if (!e) - return; + goto finish; *e = 0; From 937b1171378bc1000a34fcdfe9534d898227e35f Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Fri, 10 Aug 2018 12:55:09 +0000 Subject: [PATCH 3/3] journald: take leading spaces into account in syslog_parse_identifier 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 | 3 ++- src/journal/test-journal-syslog.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index 6dc6b0741a..72b73c2c0f 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -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) { diff --git a/src/journal/test-journal-syslog.c b/src/journal/test-journal-syslog.c index 120477cc9f..415b9d23ca 100644 --- a/src/journal/test-journal-syslog.c +++ b/src/journal/test-journal-syslog.c @@ -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);