Skip to content

Commit

Permalink
journal: Add test cases that catch out-of-bounds read in journald
Browse files Browse the repository at this point in the history
The test cases from commit 8595102 check for the return value of
syslog_parse_identifier() and will catch the condition that produced
vulnerability from CVE-2018-16866.

Add these tests to our stable branches.

Tested that these tests will fail if the fix for CVE-2018-16866 is missing
from the branch.
  • Loading branch information
filbranden authored and keszybz committed Jan 14, 2019
1 parent 33583cc commit cd12375
Showing 1 changed file with 15 additions and 5 deletions.
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;
}

0 comments on commit cd12375

Please sign in to comment.