summaryrefslogtreecommitdiffstats
path: root/src/journal
diff options
context:
space:
mode:
authorEvgeny Vereshchagin <evvers@ya.ru>2018-11-16 23:32:31 +0100
committerEvgeny Vereshchagin <evvers@ya.ru>2018-11-17 11:25:19 +0100
commit1dab14aba749b9c5ab8176c5730107b70834240b (patch)
tree2b0ad3716c496f486756c48388c20badc6f9baf8 /src/journal
parenttests: add a fuzzer for process_audit_string (diff)
downloadsystemd-1dab14aba749b9c5ab8176c5730107b70834240b.tar.xz
systemd-1dab14aba749b9c5ab8176c5730107b70834240b.zip
journald: check whether sscanf has changed the value corresponding to %n
It's possible for sscanf to receive strings containing all three fields and not matching the template at the same time. When this happens the value of k doesn't change, which basically means that process_audit_string tries to access memory randomly. Sometimes it works and sometimes it doesn't :-) See also https://bugzilla.redhat.com/show_bug.cgi?id=1059314.
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/journald-audit.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c
index 94484f5d01..345e43ef44 100644
--- a/src/journal/journald-audit.c
+++ b/src/journal/journald-audit.c
@@ -341,11 +341,12 @@ void process_audit_string(Server *s, int type, const char *data, size_t size) {
if (!p)
return;
+ k = 0;
if (sscanf(p, "(%" PRIu64 ".%" PRIu64 ":%" PRIu64 "):%n",
&seconds,
&msec,
&id,
- &k) != 3)
+ &k) != 3 || k == 0)
return;
p += k;