Skip to content

Commit a22fe90

Browse files
la14-1louisgvclaude
authored
fix: safe printf format strings and document e2e source usage (#2445)
install.sh: Replace color variable interpolation in printf format strings with %b arguments to prevent format string injection (fixes #2443). common.sh: Use %b for color escapes in logging functions. Document that BASH_SOURCE and source usage in load_cloud_driver is intentional since e2e scripts are filesystem-only, not curl|bash (fixes #2438). Agent: ux-engineer Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3724bb8 commit a22fe90

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

sh/cli/install.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ NC='\033[0m'
2424

2525
CYAN='\033[0;36m'
2626

27-
log_info() { printf "${GREEN}[spawn]${NC} %s\n" "$1"; }
28-
log_step() { printf "${CYAN}[spawn]${NC} %s\n" "$1"; }
29-
log_warn() { printf "${YELLOW}[spawn]${NC} %s\n" "$1"; }
30-
log_error() { printf "${RED}[spawn]${NC} %s\n" "$1"; }
27+
log_info() { printf '%b[spawn]%b %s\n' "$GREEN" "$NC" "$1"; }
28+
log_step() { printf '%b[spawn]%b %s\n' "$CYAN" "$NC" "$1"; }
29+
log_warn() { printf '%b[spawn]%b %s\n' "$YELLOW" "$NC" "$1"; }
30+
log_error() { printf '%b[spawn]%b %s\n' "$RED" "$NC" "$1"; }
3131

3232
# --- Helper: compare semver strings ---
3333
# Returns 0 (true) if $1 >= $2
@@ -239,9 +239,9 @@ ensure_in_path() {
239239
all_ready=false
240240
fi
241241
if [ "$all_ready" = true ]; then
242-
printf "${GREEN}[spawn]${NC} Run ${BOLD}spawn${NC} to get started\n"
242+
printf '%b[spawn]%b Run %bspawn%b to get started\n' "$GREEN" "$NC" "$BOLD" "$NC"
243243
else
244-
printf "${GREEN}[spawn]${NC} To start using spawn, run:\n"
244+
printf '%b[spawn]%b To start using spawn, run:\n' "$GREEN" "$NC"
245245
echo ""
246246
echo " exec \$SHELL"
247247
echo ""

sh/e2e/lib/common.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,39 +37,42 @@ _TRACKED_APPS=""
3737
# Logging (with optional cloud prefix for parallel output)
3838
# ---------------------------------------------------------------------------
3939
log_header() {
40-
printf "\n${BOLD}${BLUE}%s=== %s ===${NC}\n" "${CLOUD_LOG_PREFIX}" "$1"
40+
printf '\n%b%b%s=== %s ===%b\n' "$BOLD" "$BLUE" "${CLOUD_LOG_PREFIX}" "$1" "$NC"
4141
}
4242

4343
log_step() {
44-
printf "${CYAN}%s -> %s${NC}\n" "${CLOUD_LOG_PREFIX}" "$1"
44+
printf '%b%s -> %s%b\n' "$CYAN" "${CLOUD_LOG_PREFIX}" "$1" "$NC"
4545
}
4646

4747
log_ok() {
48-
printf "${GREEN}%s [PASS] %s${NC}\n" "${CLOUD_LOG_PREFIX}" "$1"
48+
printf '%b%s [PASS] %s%b\n' "$GREEN" "${CLOUD_LOG_PREFIX}" "$1" "$NC"
4949
}
5050

5151
log_err() {
52-
printf "${RED}%s [FAIL] %s${NC}\n" "${CLOUD_LOG_PREFIX}" "$1"
52+
printf '%b%s [FAIL] %s%b\n' "$RED" "${CLOUD_LOG_PREFIX}" "$1" "$NC"
5353
}
5454

5555
log_warn() {
56-
printf "${YELLOW}%s [WARN] %s${NC}\n" "${CLOUD_LOG_PREFIX}" "$1"
56+
printf '%b%s [WARN] %s%b\n' "$YELLOW" "${CLOUD_LOG_PREFIX}" "$1" "$NC"
5757
}
5858

5959
log_info() {
60-
printf "${BLUE}%s [INFO] %s${NC}\n" "${CLOUD_LOG_PREFIX}" "$1"
60+
printf '%b%s [INFO] %s%b\n' "$BLUE" "${CLOUD_LOG_PREFIX}" "$1" "$NC"
6161
}
6262

6363
# ---------------------------------------------------------------------------
6464
# load_cloud_driver CLOUD
6565
#
6666
# Sources the cloud-specific driver and sets ACTIVE_CLOUD for wrapper dispatch.
67+
# NOTE: Uses BASH_SOURCE and source with a filesystem path. This is intentional —
68+
# e2e scripts are always run from the filesystem, never via bash <(curl ...).
6769
# ---------------------------------------------------------------------------
6870
load_cloud_driver() {
6971
local cloud="$1"
7072
ACTIVE_CLOUD="${cloud}"
7173

72-
# Resolve driver file (relative to this script's location)
74+
# Resolve driver file (relative to this script's location).
75+
# BASH_SOURCE[0] is safe here — e2e scripts run from disk, not curl|bash.
7376
local driver_dir
7477
driver_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/clouds"
7578
local driver_file="${driver_dir}/${cloud}.sh"
@@ -79,6 +82,7 @@ load_cloud_driver() {
7982
return 1
8083
fi
8184

85+
# shellcheck source=/dev/null # driver path is dynamic
8286
source "${driver_file}"
8387

8488
log_step "Loaded cloud driver: ${cloud}"

0 commit comments

Comments
 (0)