If the chroot is exited with nonzero status, kiss-chroot runs die chroot failed.
Then, die runs exit 1 which causes the EXIT trap to
execute. However, in this scope, "$@" is "chroot failed", so the trap
evaluates $1 to be "chroot" rather than the mountpoint given to the
kiss-chroot script. Then, the trap tries to unmount "chroot/dev" etc
rather than the true mountpoint.
This patch uses double quotes rather than single when setting the trap,
so that $1 is expanded then and the mountpoint is stored for when the
trap is called.
To reproduce the bug:
# /mnt/bin/kiss-chroot /mnt
...
/ # exit 1
-> chroot failed.
-> Unmounting host paths.
umount chroot/dev/shm
umount chroot/dev/pts
umount: chroot/dev/pts: no mount point specified.
umount chroot/dev
umount: chroot/dev: no mount point specified.
umount chroot/proc
umount: chroot/proc: no mount point specified.
umount chroot/run
umount: chroot/run: no mount point specified.
umount chroot/sys/firmware/efi/efivars
umount chroot/sys
umount: chroot/sys: no mount point specified.
umount chroot/tmp
umount: chroot/tmp: no mount point specified.
umount chroot/etc/resolv.conf
umount: chroot/etc/resolv.conf: no mount point specified.
If the chroot is exited with nonzero status, kiss-chroot runs
die chroot failed
. Then, die runsexit 1
which causes the EXIT trap to execute. However, in this scope, "$@" is "chroot failed", so the trap evaluates $1 to be "chroot" rather than the mountpoint given to the kiss-chroot script. Then, the trap tries to unmount "chroot/dev" etc rather than the true mountpoint.This patch uses double quotes rather than single when setting the trap, so that $1 is expanded then and the mountpoint is stored for when the trap is called.
To reproduce the bug: