Skip to content

fix(cli): quote the installer's temporary directory in the EXIT trap - #217

Open
AshGodfrey wants to merge 1 commit into
mainfrom
ash/cli-install-trap-quoting
Open

AshGodfrey wants to merge 1 commit into
mainfrom
ash/cli-install-trap-quoting

Conversation

@AshGodfrey

@AshGodfrey AshGodfrey commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

The generated scripts/install.sh registered its cleanup as trap "rm -rf $tmp_dir" EXIT. The path was expanded when the trap was set and the resulting string was parsed again as shell code when the script exited. With a TMPDIR containing whitespace, rm -rf received several arguments and deleted paths that were not the temp directory, leaving the real one behind. With shell syntax such as $(...) in the path, that text ran on exit. Both cases exited 0.

Change

  • tmp_dir is script-scoped rather than local, so it still exists when the EXIT trap runs.
  • A failed mktemp -d aborts the install instead of continuing with an empty path.
  • The trap is trap 'rm -rf -- "$tmp_dir"' EXIT, so the path is expanded only when the trap fires, quoted, and never treated as options.

Template: templates/templates/cli/release/install.sh.stmpl. Release snapshot and the review CLI fixture regenerated.

Verification

Ran the regenerated review installer with a stub curl and TMPDIR set to a directory whose name contains a space, and to one containing $(touch pwned):

  • install completes and the binary is placed
  • the temp directory is removed in both cases
  • the sibling directory next to the "space" path is untouched
  • no pwned file appears in the working directory

bash -n passes on the generated script. UPDATE_SNAPS=1 go test ./pkg/generate/snapshots -run 'TestSnapCLIRelease|TestSnapCLIInstallDocs' updated and passes.


Summary by cubic

Fixes the generated install.sh cleanup trap so installing with a TMPDIR containing whitespace or shell syntax no longer deletes unrelated paths or executes path text on exit.

  • The trap now expands the temporary directory path only when it fires, quoted and after a -- guard.
  • tmp_dir is script-scoped so it still exists when the trap runs, and a failed mktemp -d aborts the install instead of continuing with an empty path.

Written for commit ffb57bf. Summary will update on new commits.

View guided diff Turn on auto-fix

The generated install.sh set its cleanup trap with the temporary path
expanded at trap time and unquoted, so a path containing whitespace or
shell syntax was re-parsed when the trap fired: rm -rf could remove
unrelated paths and command substitutions in the path were executed.

The directory variable is now script-scoped so it is still defined when
the trap runs, mktemp failure aborts the install, and the trap expands
the path only when it executes, quoted and after a -- guard.
@AshGodfrey
AshGodfrey requested a review from a team as a code owner November 16, 2026 17:45
@AshGodfrey
AshGodfrey requested a review from mfbx9da4 November 16, 2026 17:45

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Fixes a shell-quoting bug in the generated installer's EXIT trap so a TMPDIR containing whitespace or shell syntax is safely quoted and removed; the focused template change is backed by regenerated snapshot fixtures and a changeset.

View guided diff | Turn on auto-fix | Re-trigger cubic

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