Skip to content

Commit 04193fb

Browse files
committed
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.
1 parent 1890c53 commit 04193fb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/test/test-exec-util.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ static void test_environment_gathering(void) {
324324
assert_se(chmod(name3, 0755) == 0);
325325

326326
/* When booting in containers or without initramfs there might not be
327-
* any PATH in the environ and if there is no PATH /bin/sh built-in
327+
* any PATH in the environment and if there is no PATH /bin/sh built-in
328328
* PATH may leak and override systemd's DEFAULT_PATH which is not
329329
* good. Force our own PATH in environment, to prevent expansion of sh
330330
* built-in $PATH */
@@ -361,7 +361,10 @@ static void test_environment_gathering(void) {
361361
assert_se(streq(strv_env_get(env, "PATH"), DEFAULT_PATH ":/no/such/file"));
362362

363363
/* reset environ PATH */
364-
(void) setenv("PATH", old, 1);
364+
if (old)
365+
(void) setenv("PATH", old, 1);
366+
else
367+
(void) unsetenv("PATH");
365368
}
366369

367370
static void test_error_catching(void) {

0 commit comments

Comments
 (0)