Skip to content

fix(ensure-shutdown): apply timeout default under nounset#369

Open
maybebyte wants to merge 1 commit into
Kicksecure:masterfrom
maybebyte:fix/ensure-shutdown-nounset-default
Open

fix(ensure-shutdown): apply timeout default under nounset#369
maybebyte wants to merge 1 commit into
Kicksecure:masterfrom
maybebyte:fix/ensure-shutdown-nounset-default

Conversation

@maybebyte

Copy link
Copy Markdown
Contributor

Summary

ensure-shutdown's built-in ENSURE_SHUTDOWN_TIMEOUT fallback is unreachable under set -o nounset. When no config file assigns the variable, the guard aborts the script instead of defaulting to 30, so the forced-shutdown watchdog (ExecStart) never starts.

Changes

  • Root cause: the guard tests [ -z "${ENSURE_SHUTDOWN_TIMEOUT}" ] with no :- default. Under nounset, expanding the unset variable raises unbound variable and exits before the =30 fallback can run. Add the :- default (${ENSURE_SHUTDOWN_TIMEOUT:-}) so the guard evaluates and applies the default. The is_whole_number call on the next line is unchanged — it is only reached when the variable is set.

Testing

  • bash -n on the patched script — OK.
  • Minimal repro under set -o nounset, variable unset: pre-fix [ -z "${VAR}" ]VAR: unbound variable, exit 127, fallback never runs; post-fix [ -z "${VAR:-}" ] → prints the fallback branch, exit 0.

Notes for reviewers

  • Not a default-install regression: the shipped etc/security-misc/emerg-shutdown/30_security_misc.conf sets ENSURE_SHUTDOWN_TIMEOUT=30, so this only bites a config that no longer assigns it (e.g. an admin edits the conffile trusting the script's advertised default). The sibling emerg-shutdown wrapper avoids the same trap by pre-initializing its config variables before sourcing.

The script runs under 'set -o nounset'. When no config file assigns
ENSURE_SHUTDOWN_TIMEOUT, the bare "${ENSURE_SHUTDOWN_TIMEOUT}" in the
fallback guard raises an unbound-variable error and aborts before the
guard can apply the default, so ExecStart never starts the shutdown
monitor. Add the ':-' default in the -z test so the guard runs and
falls back to 30. The sibling emerg-shutdown wrapper avoids this by
pre-initializing its config variables before sourcing.
@maybebyte

Copy link
Copy Markdown
Contributor Author

AI assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant