Package: live-build Version: 1:20240810 Severity: normal X-Debbugs-Cc: adrela...@kicksecure.com
Expected result: I should be able to specify arbitrary environment variables in config/environment.chroot and have them be picked up by commands that run within the chroot. Actual result: If I specify an environment variable that includes a space in the variable's value (for instance, TEST_ENV_VAR='abc def ghi'), the build crashes with `/usr/bin/env: 'def': No such file or directory`. Steps to reproduce: * Create a new directory, 'test-build', and change to it. * Run `lb config` to create a base configuration. * Create `config/environment.chroot` with the following contents: TEST_ENV_VAR='abc def ghi' * Run `sudo lb build`. The ISO build will fail partway through as described above. From looking at the source code, it appears that the `/usr/bin/env` call that is failing is at https://salsa.debian.org/live-team/live-build/-/blob/master/functions/chroot.sh?ref_type=heads#L32, which attempts to use the shell's word splitting feature to convert a space-separated string into multiple arguments, each one corresponding to an environment variable. This doesn't work when one of the environment variables has a space in it though, because the shell's word splitting will split on *any* space, *even spaces within quotes,* in this scenario. You can reproduce this in a Bash shell with the following one-liner: fn () { echo $#; }; var="TEST_ENV_VAR='abc def ghi'"; fn $var The output will be '3', rather than the '1' you might expect. I've tried multiple ways of solving this, all without success: * Using `eval` to run the `env` command. The idea behind this is that the calling shell can expand the ENV variable, then `eval` will cause the command to be re-parsed, thus causing the quotes to be recognized and fixing the word splitting issue. I can't seem to escape the right combination of things in the `env` command to make this work, and I corrupted a VM trying, so I wouldn't recommend pursuing this without caution. * Trying various forms of quoting the variable differently. This doesn't work because word splitting is ignoring the nested quotes entirely. * Removing bashism checks from live-build, forcing the use of bash, and then using an array for ENV instead. This allowed me to use array expansion rather than usual variable expansion. This seemed to work at first surface, but for some reason the actual command called by `env` seemed to not be recognizing the environment variables I passed in. * Hijacking the `env` call by making the contents of `environment.chroot` point to the name of a script, which I then attempted to include using the `includes.chroot_after_packages` directory. The script's job was to simply set the correct environment variables, then run the command. This didn't work because the first place where `Chroot` is called is in one of the bootstrap scripts. No includes are extracted yet at that point. * Groaning while looking at the screen. Sadly, the screen is either deaf or completely devoid of compassion. I am encountering this issue on Debian 12, using a backported build of live-build. My system information shows Ubuntu because I used an Ubuntu computer to write the bug report. -- System Information: Debian Release: trixie/sid APT prefers noble-updates APT policy: (500, 'noble-updates'), (500, 'noble-security'), (500, 'noble'), (100, 'noble-backports') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 6.8.0-45-kfocus (SMP w/16 CPU threads; PREEMPT) Kernel taint flags: TAINT_USER, TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set Shell: /bin/sh linked to /usr/bin/dash Init: systemd (via /run/systemd/system) LSM: AppArmor: enabled Versions of packages live-build depends on: ii cpio 2.15+dfsg-1ubuntu2 ii debootstrap 1.0.134ubuntu1 ii initramfs-tools 0.142ubuntu25.4 live-build recommends no packages. Versions of packages live-build suggests: ii dosfstools 4.2-1.1build1 ii fakeroot 1.33-1 ii genisoimage 9:1.1.11-3.5 ii git 1:2.43.0-1ubuntu7.1 pn gnu-fdisk <none> ii memtest86+ 7.00-1build1 pn mtools <none> ii parted 3.6-4build1 ii squashfs-tools 1:4.6.1-1build1 ii sudo 1.9.15p5-3ubuntu5 pn syslinux | grub <none> ii uuid-runtime 2.39.3-9ubuntu6.1 pn win32-loader <none>