[SV 57674] Use the system default PATH if $PATH is not set
When using execvp() if $PATH is not present in the environment
it will automatically search the system default PATH string. Emulate
this by passing the system default PATH to find_in_given_path() if
we don't find PATH in the environment.
* src/job.c (child_execute_job): Use confstr(_CS_PATH) if PATH is not
found.
diff --git a/src/job.c b/src/job.c
index 94835c0..c4e7749 100644
--- a/src/job.c
+++ b/src/job.c
@@ -2381,6 +2381,18 @@
break;
}
+ /* execvp() will use a default PATH if none is set; emulate that. */
+ if (p == NULL)
+ {
+ size_t l = confstr (_CS_PATH, NULL, 0);
+ if (l)
+ {
+ char *dp = alloca (l);
+ confstr (_CS_PATH, dp, l);
+ p = dp;
+ }
+ }
+
cmd = (char *)find_in_given_path (argv[0], p, 0);
}
diff --git a/tests/scripts/misc/general4 b/tests/scripts/misc/general4
index 263505e..0077c89 100644
--- a/tests/scripts/misc/general4
+++ b/tests/scripts/misc/general4
@@ -118,4 +118,11 @@
unlink($sname);
+# SV 57674: ensure we use a system default PATH if one is not set
+delete $ENV{PATH};
+run_make_test(q!
+a: ; @echo hi
+!,
+ '', "hi\n");
+
1;