X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ftest%2Ftest-unit-file.c;h=22ac76de564b15ae49e0a989ba143a81031ee2ff;hb=4b3eff61640672bf0b19cb8cdd88ce5e84dcda1c;hp=6a146a702f85690ad5643bfd2b96219295d794bc;hpb=c853953658865ec3b3487e3f1eb2cc0516320bf3;p=elogind.git diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index 6a146a702..22ac76de5 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -20,7 +20,6 @@ along with systemd; If not, see . ***/ -#include #include #include #include @@ -73,15 +72,20 @@ static void check_execcommand(ExecCommand *c, const char* argv1, const char* argv2, bool ignore) { + size_t n; + assert_se(c); log_info("expect: \"%s\" [\"%s\" \"%s\" \"%s\"]", path, argv0 ?: path, argv1, argv2); + n = strv_length(c->argv); log_info("actual: \"%s\" [\"%s\" \"%s\" \"%s\"]", - c->path, c->argv[0], c->argv[1], c->argv[2]); + c->path, c->argv[0], n > 0 ? c->argv[1] : NULL, n > 1 ? c->argv[2] : NULL); assert_se(streq(c->path, path)); assert_se(streq(c->argv[0], argv0 ?: path)); - assert_se(streq_ptr(c->argv[1], argv1)); - assert_se(streq_ptr(c->argv[2], argv2)); + if (n > 0) + assert_se(streq_ptr(c->argv[1], argv1)); + if (n > 1) + assert_se(streq_ptr(c->argv[2], argv2)); assert_se(c->ignore == ignore); } @@ -132,6 +136,20 @@ static void test_config_parse_exec(void) { c1 = c1->command_next; check_execcommand(c1, "/RValue/slashes2", "///argv0", "r1", NULL, false); + log_info("/* honour_argv0, no args */"); + r = config_parse_exec(NULL, "fake", 3, "section", 1, + "LValue", 0, "@/RValue", + &c, NULL); + assert_se(r == 0); + assert_se(c1->command_next == NULL); + + log_info("/* no command, check for bad memory access */"); + r = config_parse_exec(NULL, "fake", 3, "section", 1, + "LValue", 0, " ", + &c, NULL); + assert_se(r == 0); + assert_se(c1->command_next == NULL); + log_info("/* ignore && honour_argv0 */"); r = config_parse_exec(NULL, "fake", 4, "section", 1, "LValue", 0, "-@/RValue///slashes3 argv0a r1",