From: =?utf-8?q?Dagfinn_Ilmari_Manns=C3=A5ker?= Date: Tue, 13 Nov 2018 16:00:48 +0000 Subject: Avoid mangling /bin non-perl shebangs on merged-/usr systems If the shebang is absolute and exists in PATH, but was not the first one found, leave it alone if it's actually the same file as first one. This avoids packages built on merged-/usr systems with /usr/bin before /bin in the path breaking when installed on systems without merged /usr. See e.g. https://bugs.debian.org/913637. Origin: backport, https://github.com/Perl-Toolchain-Gang/ExtUtils-MakeMaker/commit/9766f9c5ffd1ac915d75b309cd18c9f42794b710 Bug: https://github.com/Perl-Toolchain-Gang/ExtUtils-MakeMaker/pull/330 Bug-Debian: https://bugs.debian.org/913637 --- cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm | 22 +++++++++++++-- cpan/ExtUtils-MakeMaker/t/fixin.t | 33 +++++++++++++++++++++- .../t/lib/MakeMaker/Test/Setup/BFD.pm | 3 ++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm b/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm index bb41b27..2e33d0a 100644 --- a/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm +++ b/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm @@ -1243,8 +1243,8 @@ sub _fixin_replace_shebang { my ( $self, $file, $line ) = @_; # Now figure out the interpreter name. - my ( $cmd, $arg ) = split ' ', $line, 2; - $cmd =~ s!^.*/!!; + my ( $origcmd, $arg ) = split ' ', $line, 2; + (my $cmd = $origcmd) =~ s!^.*/!!; # Now look (in reverse) for interpreter in absolute PATH (unless perl). my $interpreter; @@ -1270,6 +1270,24 @@ sub _fixin_replace_shebang { $interpreter = $maybefile; } } + + # If the shebang is absolute and exists in PATH, but was not + # the first one found, leave it alone if it's actually the + # same file as first one. This avoids packages built on + # merged-/usr systems with /usr/bin before /bin in the path + # breaking when installed on systems without merged /usr + if ($origcmd ne $interpreter and $self->file_name_is_absolute($origcmd)) { + my $origdir = dirname($origcmd); + if ($self->maybe_command($origcmd) && grep { $_ eq $origdir } @absdirs) { + my ($odev, $oino) = stat $origcmd; + my ($idev, $iino) = stat $interpreter; + if ($odev == $idev && $oino == $iino) { + warn "$origcmd is the same as $interpreter, leaving alone" + if $Verbose; + $interpreter = $origcmd; + } + } + } } # Figure out how to invoke interpreter on this machine. diff --git a/cpan/ExtUtils-MakeMaker/t/fixin.t b/cpan/ExtUtils-MakeMaker/t/fixin.t index 061e456..872b023 100644 --- a/cpan/ExtUtils-MakeMaker/t/fixin.t +++ b/cpan/ExtUtils-MakeMaker/t/fixin.t @@ -9,7 +9,7 @@ BEGIN { use File::Spec; -use Test::More tests => 22; +use Test::More tests => 30; use Config; use TieOut; @@ -123,3 +123,34 @@ END } ); } + +SKIP: { + eval { chmod(0755, "usrbin/interp") } + or skip "no chmod", 8; + + my $dir = getcwd(); + local $ENV{PATH} = join $Config{path_sep}, map "$dir/$_", qw(usrbin bin); + + test_fixin(< <<'END', +This is a dummy interpreter END 'Big-Dummy/test.pl' => <<'END',