Repository navigation
fix(cli): quote the installer's temporary directory in the EXIT trap - #217
Open
AshGodfrey wants to merge 1 commit into
Open
AshGodfrey wants to merge 1 commit into
AshGodfrey wants to merge 1 commit into
Conversation
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.
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The generated
scripts/install.shregistered its cleanup astrap "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 aTMPDIRcontaining whitespace,rm -rfreceived 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_diris script-scoped rather thanlocal, so it still exists when the EXIT trap runs.mktemp -daborts the install instead of continuing with an empty path.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
curlandTMPDIRset to a directory whose name contains a space, and to one containing$(touch pwned):pwnedfile appears in the working directorybash -npasses 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.shcleanup trap so installing with aTMPDIRcontaining whitespace or shell syntax no longer deletes unrelated paths or executes path text on exit.--guard.tmp_diris script-scoped so it still exists when the trap runs, and a failedmktemp -daborts the install instead of continuing with an empty path.Written for commit ffb57bf. Summary will update on new commits.