Skip to content

Commit 1e20160

Browse files
authored
cc.sh: avoid eval in bell check (#11)
Signed-off-by: Harmen Stoppels <harmenstoppels@gmail.com>
1 parent e9fb6c4 commit 1e20160

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

cc.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,11 @@ execute() {
208208
}
209209

210210
# Fail with a clear message if the input contains any bell characters.
211-
if eval "[ \"\${*#*${lsep}}\" != \"\$*\" ]"; then
212-
die "Compiler command line contains our separator ('${lsep}'). Cannot parse."
213-
fi
211+
case "$*" in
212+
*"$lsep"*)
213+
die "Compiler command line contains our separator ('${lsep}'). Cannot parse."
214+
;;
215+
esac
214216

215217
# ensure required variables are set
216218
for param in $params; do

test/run.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,19 @@ test_no_wrapper_environment() {
363363
esac
364364
}
365365

366+
test_separator_in_args() {
367+
wrapper_environment
368+
_out=$("$WRAPPER_DIR/cc" "hello$(printf '\a')world" 2>&1)
369+
_rc=$?
370+
if [ "$_rc" -eq 0 ]; then
371+
fail "cc with bell char in args unexpectedly exited 0"
372+
fi
373+
case "$_out" in
374+
*"Compiler command line contains our separator"*) ;;
375+
*) fail "expected 'Compiler command line contains our separator' in: $_out" ;;
376+
esac
377+
}
378+
366379
test_modes() {
367380
wrapper_environment
368381

@@ -1062,6 +1075,7 @@ hello.c')
10621075

10631076
all_tests='
10641077
test_no_wrapper_environment
1078+
test_separator_in_args
10651079
test_modes
10661080
test_expected_args
10671081
test_expected_args_with_flags

0 commit comments

Comments
 (0)