Only set up FAKECHROOT_CMD_SUBST for paths in PATH containing the original binary
If FAKECHROOT_CMD_SUBST sets up wrong substitutions, then binaries cannot be found. For example if /usr/bin/chroot is listed in FAKECHROOT_CMD_SUBST but /usr/sbin (the actual location of the chroot binary) is not in PATH, the command fails
This commit is contained in:
parent
158956e213
commit
e4ef326b59
3 changed files with 41 additions and 9 deletions
|
@ -312,3 +312,6 @@ Skip-If:
|
|||
hostarch != "amd64"
|
||||
mode == "fakechroot" and not run_ma_same_tests
|
||||
not have_binfmt
|
||||
|
||||
Test: no-sbin-in-path
|
||||
Modes: fakechroot
|
||||
|
|
25
mmdebstrap
25
mmdebstrap
|
@ -2346,17 +2346,24 @@ sub run_prepare {
|
|||
# /etc/fakechroot/debootstrap.env and
|
||||
# /etc/fakechroot/chroot.env
|
||||
{
|
||||
my $ldconfig = getcwd() . '/ldconfig.fakechroot';
|
||||
if (!-x $ldconfig) {
|
||||
$ldconfig = '/usr/libexec/mmdebstrap/ldconfig.fakechroot';
|
||||
my %subst = (
|
||||
chroot => "/usr/sbin/chroot.fakechroot",
|
||||
mkfifo => "/bin/true",
|
||||
ldconfig => (getcwd() . '/ldconfig.fakechroot'),
|
||||
ldd => "/usr/bin/ldd.fakechroot",
|
||||
ischroot => "/bin/true"
|
||||
);
|
||||
if (!-x $subst{ldconfig}) {
|
||||
$subst{ldconfig}
|
||||
= '/usr/libexec/mmdebstrap/ldconfig.fakechroot';
|
||||
}
|
||||
my @fakechrootsubst = ();
|
||||
foreach my $d ('/usr/sbin', '/usr/bin', '/sbin', '/bin') {
|
||||
push @fakechrootsubst, "$d/chroot=/usr/sbin/chroot.fakechroot";
|
||||
push @fakechrootsubst, "$d/mkfifo=/bin/true";
|
||||
push @fakechrootsubst, "$d/ldconfig=$ldconfig";
|
||||
push @fakechrootsubst, "$d/ldd=/usr/bin/ldd.fakechroot";
|
||||
push @fakechrootsubst, "$d/ischroot=/bin/true";
|
||||
foreach my $d (split ':', $ENV{PATH}) {
|
||||
foreach my $k (sort keys %subst) {
|
||||
if (-e "$d/$k") {
|
||||
push @fakechrootsubst, "$d/$k=$subst{$k}";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (defined $ENV{FAKECHROOT_CMD_SUBST}
|
||||
&& $ENV{FAKECHROOT_CMD_SUBST} ne "") {
|
||||
|
|
22
tests/no-sbin-in-path
Normal file
22
tests/no-sbin-in-path
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# If FAKECHROOT_CMD_SUBST sets up wrong substitutions, then binaries cannot be
|
||||
# found. For example if /usr/bin/chroot is listed in FAKECHROOT_CMD_SUBST but
|
||||
# /usr/sbin (the actual location of the chroot binary) is not in PATH, the
|
||||
# command fails
|
||||
|
||||
set -eu
|
||||
export LC_ALL=C.UTF-8
|
||||
[ "{{ MODE }}" = "fakechroot" ]
|
||||
trap "rm -f /tmp/debian-chroot.tar" EXIT INT TERM
|
||||
if [ "$(id -u)" -eq 0 ] && ! id -u user > /dev/null 2>&1; then
|
||||
if [ ! -e /mmdebstrap-testenv ]; then
|
||||
echo "this test modifies the system and should only be run inside a container" >&2
|
||||
exit 1
|
||||
fi
|
||||
adduser --gecos user --disabled-password user
|
||||
fi
|
||||
prefix=
|
||||
[ "$(id -u)" -eq 0 ] && prefix="runuser -u user --"
|
||||
$prefix env PATH=/usr/bin:/bin fakechroot fakeroot {{ CMD }} --mode=fakechroot --variant=apt {{ DIST }} /tmp/debian-chroot.tar {{ MIRROR }}
|
||||
tar -tf /tmp/debian-chroot.tar | sort | diff -u tar1.txt -
|
Loading…
Reference in a new issue