[bug #57962] apparent regression involving PATH resolution

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug #57962] apparent regression involving PATH resolution

anonymous
URL:
  <https://savannah.gnu.org/bugs/?57962>

                 Summary: apparent regression involving PATH resolution
                 Project: make
            Submitted by: misfit
            Submitted on: Fri 06 Mar 2020 04:24:40 AM UTC
                Severity: 3 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
       Component Version: None
        Operating System: None
           Fixed Release: None
           Triage Status: None

    _______________________________________________________

Details:

I submitted the following to [hidden email] but didn't hear back. Apologies
if this is a duplicate, as I couldn't figure out how to search outstanding
Make bugs in Savannah.

----------------

A recent change broke use of Perl in Makefiles for me. This is because I have
a PATH element with a directory called 'perl'. Here is how to reproduce it:

     $ sudo pacman -U /var/cache/pacman/pkg/make-4.2.1-4-x86_64.pkg.tar.xz
     ...
     $ mkdir -p mybin/perl
     $ cat Makefile
     PATH=mybin:/usr/bin/

     all:
             which perl
             perl -le 'print "HELLO"'
     $ make
     which perl
     /usr/bin/perl
     perl -le 'print "HELLO"'
     HELLO
     $ sudo pacman -U /var/cache/pacman/pkg/make-4.3-1-x86_64.pkg.tar.zst
     ...
     $ make
     which perl
     /usr/bin/perl
     perl -le 'print "HELLO"'
     make: perl: Permission denied
     make: *** [Makefile:5: all] Error 127

As you can see, the problem occurs with Make 4.3.1 but not 4.2.1.





    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57962>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57962] apparent regression involving PATH resolution

anonymous
Follow-up Comment #1, bug #57962 (project make):

If you change your rule to add a special character, does it start to work?
For example if you switch it to something like:


all:
        which perl
        :; perl -le 'print "HELLO"'



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57962>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57962] apparent regression involving PATH resolution

anonymous
Follow-up Comment #2, bug #57962 (project make):

@psmith yes it works with ":; perl"

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57962>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57962] apparent regression involving PATH resolution

anonymous
Follow-up Comment #3, bug #57962 (project make):

This is a test which reproduces the bug. The bug only manifests when
USE_POSIX_SPAWN is defined.

regards, Dmitry

diff --git a/tests/scripts/features/exec b/tests/scripts/features/exec        
                                                                             
                     
index 91181f4..3e6c3fa 100644                                                
                                                                             
                     
--- a/tests/scripts/features/exec                                            
                                                                             
                     
+++ b/tests/scripts/features/exec                                            
                                                                             
                     
@@ -60,4 +60,20 @@ SHELL = #PERL#                                            
                                                                             
                     
 all:; @printf "$(ANSWER)\n";                                                
                                                                             
                     
 !, "ANSWER='$answer'", "$answer\n");                                        
                                                                             
                     
                                                                             
                                                                             
                     
+                                                                            
                                                                             
                     
+# test 16                                                                    
                                                                             
                     
+# Use sh as a shell, but create a directory called 'sh' in PATH.            
                                                                             
                     
+# https://savannah.gnu.org/bugs/?57962.                                      
                                                                             
                     
+mkdir("mybin", 0700);                                                        
                                                                             
                     
+mkdir("mybin/sh", 0700);                                                    
                                                                             
                     
+run_make_test(q!                                                            
                                                                             
                     
+SHELL:=sh                                                                    
                                                                             
                     
+PATH:=mybin:$(PATH)                                                          
                                                                             
                     
+all:; @printf "$(ANSWER)\n"                                                  
                                                                             
                     
+!, "ANSWER='$answer'", "$answer\n");                                        
                                                                             
                     
+                                                                            
                                                                             
                     
+rmdir("mybin/sh");                                                          
                                                                             
                     
+rmdir("mybin");                                                              
                                                                             
                     
+                                                                            
                                                                             
                     
+                                                                            
                                                                             
                     
 1;        



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57962>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57962] apparent regression involving PATH resolution

anonymous
Follow-up Comment #4, bug #57962 (project make):

The bug is in gnulib in function find_in_given_path.
This is a patch which fixes the bug.
The fix is likely needed for the windows specific piece of code in
find_in_given_path as well.

regards, Dmitry

diff --git a/lib/findprog-in.c b/lib/findprog-in.c
index c254f2f..d89ec00 100644
--- a/lib/findprog-in.c
+++ b/lib/findprog-in.c
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/stat.h>
 
 #include "filename.h"
 #include "concat-filename.h"
@@ -190,6 +191,7 @@ find_in_given_path (const char *progname, const char
*path,
           dir = ".";
 
         /* Try all platform-dependent suffixes.  */
+        struct stat st;
         for (i = 0; i < sizeof (suffixes) / sizeof (suffixes[0]); i++)
           {
             const char *suffix = suffixes[i];
@@ -208,7 +210,8 @@ find_in_given_path (const char *progname, const char
*path,
                    use it.  On other systems, let's hope that this program
                    is not installed setuid or setgid, so that it is ok to
                    call access() despite its design flaw.  */
-                if (eaccess (progpathname, X_OK) == 0)
+                if (eaccess (progpathname, X_OK) == 0 &&
+                        stat(progpathname, &st) == 0 && S_ISREG(st.st_mode))
                   {
                     /* Found!  */
                     if (strcmp (progpathname, progname) == 0)







    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57962>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57962] apparent regression involving PATH resolution

anonymous
Follow-up Comment #5, bug #57962 (project make):

i also submitted this patch to bug-gnulib mailing list.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57962>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57962] apparent regression involving PATH resolution

anonymous
Follow-up Comment #6, bug #57962 (project make):

Yay, thank you Dmitry


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57962>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57962] apparent regression involving PATH resolution

anonymous
Follow-up Comment #8, bug #57962 (project make):

Thank you Paul

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57962>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57962] make attempts to execute a directory found on PATH

anonymous
Update of bug #57962 (project make):

                 Summary: apparent regression involving PATH resolution =>
make attempts to execute a directory found on PATH


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57962>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57962] make attempts to execute a directory found on PATH

anonymous
Follow-up Comment #12, bug #57962 (project make):

[comment #7 comment #7:]
> I verified this fix was applied to gnulib, so it will be present in the next
release of GNU make.  Thanks!
It seems that gnulib fixed findprog but not findprog_in that GNU make uses so
the bug is still present.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57962>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57962] make attempts to execute a directory found on PATH

anonymous
Follow-up Comment #13, bug #57962 (project make):

Thanks for pointing that out!

This has been fixed in the findprog-in module in gnulib now as well.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57962>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/