From f3114e7fb5e00a0b1106a8fd3d12ac1fc27c0809 Mon Sep 17 00:00:00 2001 From: Simon Poirier Date: Mon, 25 Sep 2023 19:31:58 -0400 Subject: [PATCH] fix: fix var used before declaration in snap_validate_seed Fix use of variable declared in conditional branch and used in parent scope in snap_validate_seed. This would affect binary for images without kernel and using "set -u". (LP: #2037338) --- live-build/functions | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/live-build/functions b/live-build/functions index 19953744..c8b55773 100644 --- a/live-build/functions +++ b/live-build/functions @@ -767,9 +767,10 @@ snap_preseed() { snap_validate_seed() { local CHROOT_ROOT=$1 + local kern_major_min=undefined if [ -e ${CHROOT_ROOT}/boot/vmlinuz ]; then - local kern_major_min=$(readlink --canonicalize --no-newline ${CHROOT_ROOT}/boot/vmlinuz | grep --extended-regexp --only-matching --max-count 1 '[0-9]+\.[0-9]+') + kern_major_min=$(readlink --canonicalize --no-newline ${CHROOT_ROOT}/boot/vmlinuz | grep --extended-regexp --only-matching --max-count 1 '[0-9]+\.[0-9]+') if [ -d /usr/share/livecd-rootfs/live-build/apparmor/${kern_major_min} ]; then # if an Ubuntu version has different kernel apparmor features between LTS and HWE kernels # a snap pre-seeding issue can occur, where the incorrect apparmor features are reported