Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix out-of-bounds read (CVE-2018-16866) #23

Merged
merged 2 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/journal/journald-syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid)
if (t)
*identifier = t;

if (strchr(WHITESPACE, p[e]))
if (p[e] != '\0' && strchr(WHITESPACE, p[e]))
e++;
*buf = p + e;
return e;
Expand Down
20 changes: 15 additions & 5 deletions src/journal/test-journal-syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include "macro.h"
#include "string-util.h"

static void test_syslog_parse_identifier(const char* str,
const char *ident, const char*pid, int ret) {
static void test_syslog_parse_identifier(const char *str,
const char *ident, const char *pid, const char *rest, int ret) {
const char *buf = str;
_cleanup_free_ char *ident2 = NULL, *pid2 = NULL;
int ret2;
Expand All @@ -33,12 +33,22 @@ static void test_syslog_parse_identifier(const char* str,
assert_se(ret == ret2);
assert_se(ident == ident2 || streq_ptr(ident, ident2));
assert_se(pid == pid2 || streq_ptr(pid, pid2));
assert_se(streq(buf, rest));
}

int main(void) {
test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", 11);
test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, 6);
test_syslog_parse_identifier("pidu xxx", NULL, NULL, 0);
test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", "xxx", 11);
test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, "xxx", 6);
test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, " xxx", 6);
test_syslog_parse_identifier("pidu xxx", NULL, NULL, "pidu xxx", 0);
test_syslog_parse_identifier(" pidu xxx", NULL, NULL, " pidu xxx", 0);
test_syslog_parse_identifier("", NULL, NULL, "", 0);
test_syslog_parse_identifier(" ", NULL, NULL, " ", 0);
test_syslog_parse_identifier(":", "", NULL, "", 1);
test_syslog_parse_identifier(": ", "", NULL, " ", 2);
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);

return 0;
}