bugmake - Bugs: bug #57962, make attempts to execute a...


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

Submitted by:  Frederick Eaton <misfit>
Submitted on:  Fri 06 Mar 2020 04:24:40 AM UTC  
Severity:  3 - Normal Item Group:  None
Status:  Fixed Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  4.3 Operating System:  POSIX-Based
Fixed Release:  None Triage Status:  None

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Sun 24 May 2020 05:34:38 PM UTC, comment #13: 

Thanks for pointing that out!

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

Paul D. Smith <psmith>
Project Administrator
Thu 21 May 2020 09:50:10 PM UTC, comment #12: 

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.

Thu 02 Apr 2020 08:50:20 PM UTC, comment #11: 

i agree tests for find_in_given_path are supposed to be gnulib.
Test is update 3 tests make though.

Dmitry Goncharov <dgoncharov>
Thu 02 Apr 2020 08:34:11 PM UTC, comment #10: 

Not per se, although it will need to be updated (or conditioned) to work on non-POSIX systems like Windows or VMS.

My thinking was that this issue is really in the gnulib library, and hopefully they have tests to ensure it continues to work (I don't know if that's true).  I'm not sure it's our place to add tests for external functions into our test suite: we can't test the entire system!

It might not be a bad idea to add a test like this even though the problem is really in gnulib.

Paul D. Smith <psmith>
Project Administrator
Thu 02 Apr 2020 12:44:04 PM UTC, comment #9: 

Paul, i see that you decided not to apply the test in updated 3. Anything wrong with it?

Dmitry Goncharov <dgoncharov>
Thu 02 Apr 2020 04:18:12 AM UTC, comment #8: 

Thank you Paul

Frederick Eaton <misfit>
Thu 02 Apr 2020 03:57:17 AM UTC, comment #7: 

I verified this fix was applied to gnulib, so it will be present in the next release of GNU make.  Thanks!

Paul D. Smith <psmith>
Project Administrator
Sat 07 Mar 2020 04:28:23 AM UTC, comment #6: 

Yay, thank you Dmitry

Frederick Eaton <misfit>
Sat 07 Mar 2020 03:49:54 AM UTC, comment #5: 

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

Dmitry Goncharov <dgoncharov>
Sat 07 Mar 2020 03:42:09 AM UTC, comment #4: 

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)

Dmitry Goncharov <dgoncharov>
Sat 07 Mar 2020 03:40:50 AM UTC, comment #3: 

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);                                                                                                                                                          
+all:; @printf "$(ANSWER)\n"                                                                                                                                                       
+!, "ANSWER='$answer'", "$answer\n");                                                                                                                                              

Dmitry Goncharov <dgoncharov>
Fri 06 Mar 2020 03:17:41 PM UTC, comment #2: 

@psmith yes it works with ":; perl"

Frederick Eaton <misfit>
Fri 06 Mar 2020 03:02:48 PM UTC, comment #1: 

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

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

Paul D. Smith <psmith>
Project Administrator
Fri 06 Mar 2020 04:24:40 AM UTC, original submission:  

I submitted the following to -email is unavailable- 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

             which perl
             perl -le 'print "HELLO"'
     $ make
     which perl
     perl -le 'print "HELLO"'
     $ sudo pacman -U /var/cache/pacman/pkg/make-4.3-1-x86_64.pkg.tar.zst
     $ make
     which 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.

Frederick Eaton <misfit>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by dgoncharov (Posted a comment)
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by misfit (Submitted the item)
  • -email is unavailable- added by misfit

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-04-14 psmith Summaryapparent regression involving PATH resolution => make attempts to execute a directory found on PATH
    2020-04-02 psmith StatusNone => Fixed
        Open/ClosedOpen => Closed
        Component VersionNone => 4.3
        Operating SystemNone => POSIX-Based
    2020-03-06 misfit Carbon-Copy- => Added frederik@ofb.net

    Back to the top

    Powered by Savane 3.5