From 6090ce57da56b9be6c9a4ed7fabf60c8e032d772 Mon Sep 17 00:00:00 2001 From: Jan De Landtsheer Date: Tue, 9 Sep 2025 11:46:59 +0200 Subject: [PATCH] initramfs_validate: resolve path and harden existence check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Resolve input dir to absolute with resolve_path and perform early -d check in [bash.initramfs_validate()](scripts/lib/initramfs.sh:774) to avoid safe_execute aborts on missing paths • Use plain ls/find logging for sanity snapshot (not safe_execute) so validation reports context even if directory is absent --- scripts/lib/initramfs.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/lib/initramfs.sh b/scripts/lib/initramfs.sh index 787926f..35e6912 100644 --- a/scripts/lib/initramfs.sh +++ b/scripts/lib/initramfs.sh @@ -772,15 +772,26 @@ function initramfs_create_cpio() { # Validate initramfs contents function initramfs_validate() { - local initramfs_dir="$1" + local initramfs_dir_in="$1" + local initramfs_dir + initramfs_dir=$(resolve_path "${initramfs_dir_in}") section_header "Validating initramfs contents" local errors=0 + # Early existence check to avoid aborting via safe_execute + if [[ ! -d "${initramfs_dir}" ]]; then + log_error "Initramfs directory not found: ${initramfs_dir_in} (resolved: ${initramfs_dir})" + log_info "PWD: $(pwd)" + log_info "Listing current directory:" + ls -la . 2>/dev/null || true + return 1 + fi + # Sanity snapshot to aid debugging when validation fails log_info "Validation sanity: top-level of ${initramfs_dir}:" - safe_execute ls -la "${initramfs_dir}" || true + ls -la "${initramfs_dir}" 2>/dev/null || log_warn "Cannot list ${initramfs_dir}" local _count_sanity _count_sanity=$(find "${initramfs_dir}" -mindepth 1 | wc -l || echo "0") log_info "Validation sanity: ${_count_sanity} total entries under ${initramfs_dir}"