From 1890c538920f93c39636e6beebc1bf7d0a8bc0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 12 Apr 2019 08:55:39 +0200 Subject: test-env-util: allow $PATH to be unset Coverity was unhappy, because it doesn't know that $PATH is pretty much always set. But let's not assume that in the test. CID #1400496. $ (unset PATH; build/test-env-util) [1] 31658 segmentation fault (core dumped) ( unset PATH; build/test-env-util; ) --- src/test/test-env-util.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c index f57a26021c..17dacda70f 100644 --- a/src/test/test-env-util.c +++ b/src/test/test-env-util.c @@ -122,10 +122,10 @@ static void test_env_strv_get_n(void) { assert_se(!strv_env_get_n(env, "PATH__", 4, 0)); assert_se(!strv_env_get_n(env, "PATH", 4, 0)); - assert_se(streq(strv_env_get_n(env, "PATH__", 4, REPLACE_ENV_USE_ENVIRONMENT), - getenv("PATH"))); - assert_se(streq(strv_env_get_n(env, "PATH", 4, REPLACE_ENV_USE_ENVIRONMENT), - getenv("PATH"))); + assert_se(streq_ptr(strv_env_get_n(env, "PATH__", 4, REPLACE_ENV_USE_ENVIRONMENT), + getenv("PATH"))); + assert_se(streq_ptr(strv_env_get_n(env, "PATH", 4, REPLACE_ENV_USE_ENVIRONMENT), + getenv("PATH"))); } static void test_replace_env(bool braceless) { -- cgit v1.2.1 From 04193fb2ae2fd52a367e5437eb10bd28d27535d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 12 Apr 2019 09:00:37 +0200 Subject: test-exec-util: do not call setenv with NULL arg The comment explains that $PATH might not be set in certain circumstances and takes steps to handle this case. If we do that, let's assume that $PATH indeed might be unset and not call setenv("PATH", NULL, 1). It is not clear from the man page if that is allowed. CID #1400497. --- src/test/test-exec-util.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/test-exec-util.c b/src/test/test-exec-util.c index 25ca7a2bc9..f6f2e6317e 100644 --- a/src/test/test-exec-util.c +++ b/src/test/test-exec-util.c @@ -324,7 +324,7 @@ static void test_environment_gathering(void) { assert_se(chmod(name3, 0755) == 0); /* When booting in containers or without initramfs there might not be - * any PATH in the environ and if there is no PATH /bin/sh built-in + * any PATH in the environment and if there is no PATH /bin/sh built-in * PATH may leak and override systemd's DEFAULT_PATH which is not * good. Force our own PATH in environment, to prevent expansion of sh * built-in $PATH */ @@ -361,7 +361,10 @@ static void test_environment_gathering(void) { assert_se(streq(strv_env_get(env, "PATH"), DEFAULT_PATH ":/no/such/file")); /* reset environ PATH */ - (void) setenv("PATH", old, 1); + if (old) + (void) setenv("PATH", old, 1); + else + (void) unsetenv("PATH"); } static void test_error_catching(void) { -- cgit v1.2.1 From 17e4b07088c8772673ecd8e32b6e1d045d8004a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 12 Apr 2019 09:03:52 +0200 Subject: core: vodify one more call to mkdir CID #1400460. --- src/core/manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/manager.c b/src/core/manager.c index 4154aec12f..24559a45f3 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -288,7 +288,7 @@ static int manager_check_ask_password(Manager *m) { if (!m->ask_password_event_source) { assert(m->ask_password_inotify_fd < 0); - mkdir_p_label("/run/systemd/ask-password", 0755); + (void) mkdir_p_label("/run/systemd/ask-password", 0755); m->ask_password_inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC); if (m->ask_password_inotify_fd < 0) -- cgit v1.2.1