]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 57674] Use the system default PATH if $PATH is not set
authorPaul Smith <psmith@gnu.org>
Wed, 1 Apr 2020 05:13:02 +0000 (01:13 -0400)
committerPaul Smith <psmith@gnu.org>
Wed, 1 Apr 2020 06:02:57 +0000 (02:02 -0400)
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.

src/job.c
tests/scripts/misc/general4

index 94835c0d24af7900be55a9f2fba79ba213c231d7..c4e7749035c26ec287d2c27f437b630b98e877db 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -2381,6 +2381,18 @@ child_execute_job (struct childbase *child, int good_stdin, char **argv)
           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);
   }
 
index 263505e492f7b6d120504994e8d0bb79bb9558dd..0077c896c7944a259fe273f805e60755a94244fa 100644 (file)
@@ -118,4 +118,11 @@ all: ; $sname
 
 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;