From ffb57bf86075fe0d483e9351b2fabcc629795218 Mon Sep 17 00:00:00 2001 From: Ash Godfrey Date: Mon, 16 Nov 2026 17:45:06 +0000 Subject: [PATCH] fix(cli): quote the installer's temporary directory in the EXIT trap 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. --- .changesets/1794851020-be0a6121.yaml | 10 ++++++++++ pkg/generate/snapshots/cli_release_go_test.go | 12 ++++++------ templates/templates/cli/release/install.sh.stmpl | 4 ++-- zSDKs/sdk-cli/.speakeasy/gen.lock | 2 +- zSDKs/sdk-cli/scripts/install.sh | 4 ++-- 5 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 .changesets/1794851020-be0a6121.yaml diff --git a/.changesets/1794851020-be0a6121.yaml b/.changesets/1794851020-be0a6121.yaml new file mode 100644 index 000000000..f44e607b3 --- /dev/null +++ b/.changesets/1794851020-be0a6121.yaml @@ -0,0 +1,10 @@ +id: 1794851020-be0a6121 +features: + - core +targets: + - cli +type: fix +bump: patch +description: the generated install.sh now quotes the temporary download directory in its EXIT trap, so cleanup removes only that directory and never runs path text as shell code +author: AshGodfrey +date: "2026-11-16" diff --git a/pkg/generate/snapshots/cli_release_go_test.go b/pkg/generate/snapshots/cli_release_go_test.go index ba34dbe62..9ce794373 100644 --- a/pkg/generate/snapshots/cli_release_go_test.go +++ b/pkg/generate/snapshots/cli_release_go_test.go @@ -951,8 +951,8 @@ install_cli() { log_info "Downloading from: $download_url" # Create temporary directory - local tmp_dir=$(mktemp -d) - trap "rm -rf $tmp_dir" EXIT + tmp_dir=$(mktemp -d) || exit 1 + trap 'rm -rf -- "$tmp_dir"' EXIT # Download archive if command -v curl >/dev/null 2>&1; then @@ -2001,8 +2001,8 @@ install_cli() { log_info "Downloading from: $download_url" # Create temporary directory - local tmp_dir=$(mktemp -d) - trap "rm -rf $tmp_dir" EXIT + tmp_dir=$(mktemp -d) || exit 1 + trap 'rm -rf -- "$tmp_dir"' EXIT # Download archive if command -v curl >/dev/null 2>&1; then @@ -3110,8 +3110,8 @@ install_cli() { log_info "Downloading from: $download_url" # Create temporary directory - local tmp_dir=$(mktemp -d) - trap "rm -rf $tmp_dir" EXIT + tmp_dir=$(mktemp -d) || exit 1 + trap 'rm -rf -- "$tmp_dir"' EXIT # Download archive if command -v curl >/dev/null 2>&1; then diff --git a/templates/templates/cli/release/install.sh.stmpl b/templates/templates/cli/release/install.sh.stmpl index 070f7453d..3e0a26b9d 100644 --- a/templates/templates/cli/release/install.sh.stmpl +++ b/templates/templates/cli/release/install.sh.stmpl @@ -140,8 +140,8 @@ install_cli() { log_info "Downloading from: $download_url" # Create temporary directory - local tmp_dir=$(mktemp -d) - trap "rm -rf $tmp_dir" EXIT + tmp_dir=$(mktemp -d) || exit 1 + trap 'rm -rf -- "$tmp_dir"' EXIT # Download archive if command -v curl >/dev/null 2>&1; then diff --git a/zSDKs/sdk-cli/.speakeasy/gen.lock b/zSDKs/sdk-cli/.speakeasy/gen.lock index 1dbab381d..e0842ac43 100644 --- a/zSDKs/sdk-cli/.speakeasy/gen.lock +++ b/zSDKs/sdk-cli/.speakeasy/gen.lock @@ -668,7 +668,7 @@ trackedFiles: scripts/install.ps1: last_write_checksum: sha1:c03368407505979c2b4498d0d754c7bcda82769a scripts/install.sh: - last_write_checksum: sha1:ba255d220bc830375d4f2bc34a7ca01e0a0a8fe2 + last_write_checksum: sha1:6537dfb61f550be0ee3a98d04d1ea5ab0b790279 tests/artifact_test.go: last_write_checksum: sha1:80691e63c96f85539e12254654f82edd0511dc59 tests/async_test.go: diff --git a/zSDKs/sdk-cli/scripts/install.sh b/zSDKs/sdk-cli/scripts/install.sh index c824e5ba4..d47e9bbc0 100644 --- a/zSDKs/sdk-cli/scripts/install.sh +++ b/zSDKs/sdk-cli/scripts/install.sh @@ -140,8 +140,8 @@ install_cli() { log_info "Downloading from: $download_url" # Create temporary directory - local tmp_dir=$(mktemp -d) - trap "rm -rf $tmp_dir" EXIT + tmp_dir=$(mktemp -d) || exit 1 + trap 'rm -rf -- "$tmp_dir"' EXIT # Download archive if command -v curl >/dev/null 2>&1; then