]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-exec-util: do not call setenv with NULL arg
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 12 Apr 2019 07:00:37 +0000 (09:00 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 12 Apr 2019 07:05:02 +0000 (09:05 +0200)
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

index 25ca7a2bc939f5e9e69d31696c88a7ec912f2ba3..f6f2e6317e55eb5e289a09bd079cfa6635cb4f8c 100644 (file)
@@ -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) {