From 3eeef1e0f68d750e7817748180a2007095e99ef3 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 14 Jun 2026 15:26:24 +0300 Subject: lm0 harden resolve_config_array callers against set -e The shared resolve_config_array helper returns non-zero when the source config var was never declared. Both callers (resolve_tar_opts, resolve_sync_destinations) invoked it unconditionally and ignored the return value, so under set -euo pipefail a genuinely-unset TAR_OPTS or SYNC_DESTINATIONS would abort the function before the empty-array fallback could run. Currently masked because apply_config_defaults always declares both vars, but the contract was unsafe to rely on. Guard both call sites with `|| true` and document why: the empty array the helper leaves behind is exactly what each caller's fallback expects. Co-Authored-By: Claude Opus 4.8 --- src/lib/archive.source.sh | 5 ++++- src/lib/config.sync.source.sh | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/archive.source.sh b/src/lib/archive.source.sh index 3b173b7..b53a782 100644 --- a/src/lib/archive.source.sh +++ b/src/lib/archive.source.sh @@ -30,7 +30,10 @@ resolve_tar_opts() { # Parse TAR_OPTS (array or scalar) via the shared config-array helper, # then fall back to a plain "-c" whenever no options were configured, # whether TAR_OPTS was unset or set to an empty value. - resolve_config_array TAR_OPTS options_ref + # The helper returns non-zero when TAR_OPTS was never declared; we ignore + # that here (|| true) because the empty-array fallback below covers the + # unset case, and the bare non-zero return would otherwise trip set -e. + resolve_config_array TAR_OPTS options_ref || true if (( ${#options_ref[@]} == 0 )); then # shellcheck disable=SC2034 diff --git a/src/lib/config.sync.source.sh b/src/lib/config.sync.source.sh index 1707fe6..3d516dc 100644 --- a/src/lib/config.sync.source.sh +++ b/src/lib/config.sync.source.sh @@ -6,7 +6,10 @@ resolve_sync_destinations() { # Parse SYNC_DESTINATIONS (array or scalar) via the shared config-array # helper. Unlike TAR_OPTS there is no default: an unset or empty value # simply yields an empty destinations array for callers to validate. - resolve_config_array SYNC_DESTINATIONS destinations_ref + # The helper returns non-zero when SYNC_DESTINATIONS was never declared; + # we ignore that (|| true) since the already-empty array is exactly the + # desired result, and the bare non-zero return would otherwise trip set -e. + resolve_config_array SYNC_DESTINATIONS destinations_ref || true } sync_dist() { -- cgit v1.2.3