Skip to content

Harden rm -rf against empty or root TARGET (ShellCheck)#78

Merged
NathanNeurotic merged 1 commit into
mainfrom
codex/fix-security-issue-in-mk_kelf.sh
Jan 7, 2026
Merged

Harden rm -rf against empty or root TARGET (ShellCheck)#78
NathanNeurotic merged 1 commit into
mainfrom
codex/fix-security-issue-in-mk_kelf.sh

Conversation

@NathanNeurotic

Copy link
Copy Markdown
Owner

Motivation

  • Fix a critical ShellCheck/Codacy finding about unsafe rm -rf usage in mk_kelf.sh.
  • Ensure rm -rf never operates on root (/) or an empty/unset TARGET value.
  • Fail fast when TARGET is unset or empty using the required ${TARGET:?} pattern.
  • Preserve existing behavior for valid TARGET paths during cleanup.

Description

  • Add a POSIX validation line : "${TARGET:?TARGET is not set or empty}" immediately before removal.
  • Add an explicit guard that errors and exits if TARGET equals / using if [ "$TARGET" = "/" ]; then ... fi.
  • Use rm -rf -- "${TARGET:?}/" so ${TARGET:?} is used directly in the removal command to satisfy ShellCheck.
  • Update only mk_kelf.sh (resulting in 7 insertions and 6 deletions).

Testing

  • No automated tests were executed after this change.

Codex Task

@codacy-production

Copy link
Copy Markdown

Codacy's Analysis Summary

0 new issue (≤ 0 issue)
0 new security issue

Review Pull Request in Codacy →

AI Reviewer available: add the codacy-review label to get contextual insights without leaving GitHub.

@NathanNeurotic NathanNeurotic merged commit e81efbb into main Jan 7, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant