#1106774 lei fails if you have '.' in your path and a git directory

Package:
lei
Source:
lei
Submitter:
James.Bottomley@HansenPartnership.com
Date:
2026-03-09 10:09:01 UTC
Severity:
normal
Tags:
#1106774#5
Date:
2025-05-29 15:31:00 UTC
From:
To:
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 particuar, 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

#1106774#10
Date:
2025-05-29 15:42:49 UTC
From:
To:
This is the fix I sent upstream:

https://public-inbox.org/meta/a67340a12b17379ad947f8ac96cd5c0524831741.camel@HansenPartnership.com/

James
--- diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index 1d9f9b76..7f669fc6 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -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 $p); } undef; }
#1106774#15
Date:
2026-01-30 12:40:40 UTC
From:
To:
Caught by this with:

PATH=.../usr/my/bin:...:/usr/bin:...

$ ls -la /usr/my/bin/git
total 8
drwxr-xr-x 1 tj tj   90 2024-10-22 16:48 .
drwxr-xr-x 1 tj tj 2882 2026-01-25 18:03 ..
-rwxr-xr-x 1 tj tj 1077 2024-10-22 15:04 git-commit-in-debian-kernel
-rwxr-xr-x 1 tj tj  365 2024-10-22 14:15 git-find-backports

$ public-inbox-init -V2 lkml ./lkml https://lore.kernel.org/lkml linux-kernel@vger.kernel.org
Can't exec "/usr/my/bin/git": Permission denied at /usr/share/perl5/PublicInbox/SpawnPP.pm line 61.
exec /usr/my/bin/git --git-dir=./email-lists/lkml/all.git config core.sharedRepository failed: Permission denied at /usr/share/perl5/PublicInbox/SpawnPP.pm line 62.
fork_exec git --git-dir=./email-lists/lkml/all.git config core.sharedRepository failed: Permission denied

#1106774#20
Date:
2026-03-09 10:01:01 UTC
From:
To:
Control: tag -1 fixed-upstream

https://public-inbox.org/public-inbox.git/commit/?id=4cca3dcfe2342b2dfa41fb0b272c18626ae03196

is where it was applied upstream and that commit is part of upstream
tag v2.0.0.