]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
fix git permission denied in certain configs
authorJames Bottomley <James.Bottomley@HansenPartnership.com>
Thu, 29 May 2025 15:23:21 +0000 (11:23 -0400)
committerEric Wong <e@80x24.org>
Wed, 4 Jun 2025 11:37:25 +0000 (11:37 +0000)
The problem is the which() sub in Spawn.pm only checks if the path
fragment is executable, but this may be true of a directory as well.

In particular, a lot of people have a git directory in their $HOME
(where they store their git repos) and if $PATH contains '.' then
SpawnPP.pm will try to execute this directory leading to this failure
on a lot of lei commands:

exec ./git var GIT_PAGER failed: Permission denied at /usr/share/perl5/PublicInbox/SpawnPP.pm line 62.
fork_exec git var GIT_PAGER failed: Permission denied

As you can see what's happened is it's tried to execute my ./git
directory, which obviously fails.  The fix is simple, skip executable
files which are also directories when doing $PATH based lookup

[ew: use `_' bareword to avoid 2nd stat, spelling fix in commit message]

Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
lib/PublicInbox/Spawn.pm

index 1d9f9b76b1d41d0461a0039de995c418a7bafa23..7d4671c36c60e70c1fbc93d44f4ada7b14bcb3ae 100644 (file)
@@ -350,7 +350,7 @@ sub which ($) {
        return $file if index($file, '/') >= 0;
        for my $p (split(/:/, $ENV{PATH})) {
                $p .= "/$file";
-               return $p if -x $p;
+               return $p if (-x $p && ! -d _);
        }
        undef;
 }