diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-03-12 20:41:14 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-03-13 17:07:02 +0100 |
commit | ef9fafbd9143a1d6278f65ce857735ad08c79f66 (patch) | |
tree | 2fe17846f2d9451a996cba8650703327d8d1dd29 /src | |
parent | cc5957dca055bfdc6df24af47f6687d1ba1a3d7a (diff) | |
download | systemd-ef9fafbd9143a1d6278f65ce857735ad08c79f66.tar.gz systemd-ef9fafbd9143a1d6278f65ce857735ad08c79f66.tar.bz2 systemd-ef9fafbd9143a1d6278f65ce857735ad08c79f66.zip |
tests: add tests for embedded newlines in /proc/cmdline
Prompted by: #7097
Diffstat (limited to 'src')
-rw-r--r-- | src/test/test-proc-cmdline.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/test/test-proc-cmdline.c b/src/test/test-proc-cmdline.c index b0fc217d51..4e209de5b6 100644 --- a/src/test/test-proc-cmdline.c +++ b/src/test/test-proc-cmdline.c @@ -92,7 +92,7 @@ static void test_proc_cmdline_get_key(void) { _cleanup_free_ char *value = NULL; log_info("/* %s */", __func__); - assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm spaaace='ö ü ß' ticks=\"''\"") == 0); + assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm spaaace='ö ü ß' ticks=\"''\"\n\nkkk=uuu\n\n\n") == 0); assert_se(proc_cmdline_get_key("", 0, &value) == -EINVAL); assert_se(proc_cmdline_get_key("abc", 0, NULL) == 0); @@ -129,13 +129,16 @@ static void test_proc_cmdline_get_key(void) { value = mfree(value); assert_se(proc_cmdline_get_key("ticks", 0, &value) > 0 && streq_ptr(value, "''")); + value = mfree(value); + + assert_se(proc_cmdline_get_key("kkk", 0, &value) > 0 && streq_ptr(value, "uuu")); } static void test_proc_cmdline_get_bool(void) { bool value = false; log_info("/* %s */", __func__); - assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar bar-waldo=1 x_y-z=0 quux=miep") == 0); + assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar bar-waldo=1 x_y-z=0 quux=miep\nda=yes\nthe=1") == 0); assert_se(proc_cmdline_get_bool("", &value) == -EINVAL); assert_se(proc_cmdline_get_bool("abc", &value) == 0 && value == false); @@ -148,13 +151,15 @@ static void test_proc_cmdline_get_bool(void) { assert_se(proc_cmdline_get_bool("x-y_z", &value) > 0 && value == false); assert_se(proc_cmdline_get_bool("x_y_z", &value) > 0 && value == false); assert_se(proc_cmdline_get_bool("quux", &value) == -EINVAL && value == false); + assert_se(proc_cmdline_get_bool("da", &value) > 0 && value == true); + assert_se(proc_cmdline_get_bool("the", &value) > 0 && value == true); } static void test_proc_cmdline_get_key_many(void) { - _cleanup_free_ char *value1 = NULL, *value2 = NULL, *value3 = NULL, *value4 = NULL, *value5 = NULL, *value6 = NULL; + _cleanup_free_ char *value1 = NULL, *value2 = NULL, *value3 = NULL, *value4 = NULL, *value5 = NULL, *value6 = NULL, *value7 = NULL; log_info("/* %s */", __func__); - assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm SPACE='one two' doubleticks=\" aaa aaa \"") == 0); + assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm SPACE='one two' doubleticks=\" aaa aaa \"\n\nzummm='\n'\n") == 0); assert_se(proc_cmdline_get_key_many(0, "wuff-piep", &value3, @@ -162,7 +167,9 @@ static void test_proc_cmdline_get_key_many(void) { "idontexist", &value2, "zumm", &value4, "SPACE", &value5, - "doubleticks", &value6) == 4); + "doubleticks", &value6, + "zummm", &value7) == 5); + assert_se(streq_ptr(value1, "quux")); assert_se(!value2); @@ -170,6 +177,7 @@ static void test_proc_cmdline_get_key_many(void) { assert_se(!value4); assert_se(streq_ptr(value5, "one two")); assert_se(streq_ptr(value6, " aaa aaa ")); + assert_se(streq_ptr(value7, "\n")); } static void test_proc_cmdline_key_streq(void) { |