From f06a6bcd761f2a643377b17c16776512404ac3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 6 Nov 2016 01:01:17 -0400 Subject: [PATCH] test-journal-importer: add a test case with broken input --- Makefile.am | 3 ++- src/test/test-journal-importer.c | 18 +++++++++++++++++- test/journal-data/journal-2.txt | Bin 0 -> 513 bytes 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/journal-data/journal-2.txt diff --git a/Makefile.am b/Makefile.am index fef13fabcd..10839e922a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2470,7 +2470,8 @@ test_journal_importer_LDADD = \ libsystemd-shared.la EXTRA_DIST += \ - test/journal-data/journal-1.txt + test/journal-data/journal-1.txt \ + test/journal-data/journal-2.txt # ------------------------------------------------------------------------------ ## .PHONY so it always rebuilds it diff --git a/src/test/test-journal-importer.c b/src/test/test-journal-importer.c index fea5c1d51c..1f0684863e 100644 --- a/src/test/test-journal-importer.c +++ b/src/test/test-journal-importer.c @@ -44,7 +44,7 @@ static void test_basic_parsing(void) { do r = journal_importer_process_data(&imp); - while (r == 0); + while (r == 0 && !journal_importer_eof(&imp)); assert_se(r == 1); /* We read one entry, so we should get EOF on next read, but not yet */ @@ -64,11 +64,27 @@ static void test_basic_parsing(void) { assert_se(journal_importer_eof(&imp)); } +static void test_bad_input(void) { + _cleanup_(journal_importer_cleanup) JournalImporter imp = {}; + int r; + + imp.fd = open(TEST_DATA_DIR("/journal-data/journal-2.txt"), O_RDONLY|O_CLOEXEC); + assert_se(imp.fd >= 0); + + do + r = journal_importer_process_data(&imp); + while (!journal_importer_eof(&imp)); + assert_se(r == 0); /* If we don't have enough input, 0 is returned */ + + assert_se(journal_importer_eof(&imp)); +} + int main(int argc, char **argv) { log_set_max_level(LOG_DEBUG); log_parse_environment(); test_basic_parsing(); + test_bad_input(); return 0; } diff --git a/test/journal-data/journal-2.txt b/test/journal-data/journal-2.txt new file mode 100644 index 0000000000000000000000000000000000000000..4f582a0e88946303ceee7dfa21602b63632bcbfc GIT binary patch literal 513 zcmbW!(N4lJ6vlDA-BWzw3KF7}DGFgGCZac*nBbK+r0Y&uL)Vhi4jE7FBe*R-0HJqH zbAD<6{aCHn&u^>b_xh?|pX?QdfN7fErx=DNM5>C7@=Qft?KgB(w2#KSO(|VriEsAJ z2wtNO#5m|e~mgm!4f?0JFWe~Y}qsXb1TFP4gOsdgAvK147n zauG^e3oAn$EfV0hMKL(*N`o=1aRf1)j$s^@l`m>bPptxMhoeh1(QDhD(HApf-ZQ#q z+87gL5V*x8IV;w?Z@b_i*~r{d=-y|XBks#-mKAli%514?r@Fs_hK!gTAG8p6v-xaJ L;;~C1vo!ew_xGxy literal 0 HcmV?d00001