From: Zbigniew Jędrzejewski-Szmek Date: Thu, 21 Sep 2017 12:36:12 +0000 (+0200) Subject: test-conf-parser: add tests for the new long lines, including overflow handling X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8526644b08722ce6cb0c7b050ada8127e1702746;p=elogind.git test-conf-parser: add tests for the new long lines, including overflow handling --- diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c index ef8a85a47..caac43822 100644 --- a/src/test/test-conf-parser.c +++ b/src/test/test-conf-parser.c @@ -235,6 +235,10 @@ static void test_config_parse_iec_uint64(void) { } #endif // 0 +#define x10(x) x x x x x x x x x x +#define x100(x) x10(x10(x)) +#define x1000(x) x10(x100(x)) + static const char* const config_file[] = { "[Section]\n" "setting1=1\n", @@ -261,6 +265,24 @@ static const char* const config_file[] = { "\\\\2\n", /* note that C requires one level of escaping, so the * parser gets "…1 BS BS BS NL BS BS 2 NL", which * it translates into "…1 BS BS SP BS BS 2" */ + + "\n[Section]\n\n" + "setting1=" /* a line above LINE_MAX length */ + x1000("ABCD") + "\n", + + "[Section]\n" + "setting1=" /* a line above LINE_MAX length, with continuation */ + x1000("ABCD") "\\\n" + "foobar", + + "[Section]\n" + "setting1=" /* a line above the allowed limit: 9 + 1050000 + 1 */ + x1000(x1000("x") x10("abcde")) "\n", + + "[Section]\n" + "setting1=" /* many continuation lines, together above the limit */ + x1000(x1000("x") x10("abcde") "\\\n") "xxx", }; static void test_config_parse(unsigned i, const char *s) { @@ -300,20 +322,37 @@ static void test_config_parse(unsigned i, const char *s) { "Section\0", config_item_table_lookup, items, false, false, true, NULL); - assert_se(r == 0); switch (i) { case 0 ... 3: + assert_se(r == 0); assert_se(streq(setting1, "1")); break; case 4: + assert_se(r == 0); assert_se(streq(setting1, "1 2 3")); break; case 5: + assert_se(r == 0); assert_se(streq(setting1, "1\\\\ \\\\2")); break; + + case 6: + assert_se(r == 0); + assert_se(streq(setting1, x1000("ABCD"))); + break; + + case 7: + assert_se(r == 0); + assert_se(streq(setting1, x1000("ABCD") " foobar")); + break; + + case 8 ... 9: + assert_se(r == -ENOBUFS); + assert_se(setting1 == NULL); + break; } }