aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-03-23 07:52:50 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-03-23 07:52:50 -0700
commite0a110da6ff3595d2557d86c6df0f15f6ed45593 (patch)
tree665d7d485d7f5c2ac6101ff3415396af67883b4e
parent4e2856ddbea81e48bee950767fa4ac1a5ff6c453 (diff)
downloadcppawk-e0a110da6ff3595d2557d86c6df0f15f6ed45593.tar.gz
cppawk-e0a110da6ff3595d2557d86c6df0f15f6ed45593.tar.bz2
cppawk-e0a110da6ff3595d2557d86c6df0f15f6ed45593.zip
hygiene: shell escape $awk and $prepro.
Since $awk and $prepro are now controlled via command line options, and are being fed to eval, we should shell escape them. Two of our test cases rely on the loose interpolation behavior; we fix those using proper external mock programs testawk and testcpp.
-rwxr-xr-xcppawk23
-rwxr-xr-xtestawk3
-rw-r--r--testcases6
-rwxr-xr-xtestcpp3
4 files changed, 14 insertions, 21 deletions
diff --git a/cppawk b/cppawk
index 35cfffb..867308a 100755
--- a/cppawk
+++ b/cppawk
@@ -151,28 +151,15 @@ while [ $# -gt 0 ] ; do
shift
done
-case $awk in
- 'command '* )
- ;;
- * )
- awk="command $awk"
- ;;
-esac
-
-case $prepro in
- 'command '* )
- ;;
- * )
- prepro="command $prepro"
- ;;
-esac
+awk="command $(quote "$awk")"
+prepro="command $(quote "$prepro")"
trap 'rm -f $tmp_file' EXIT INT TERM
if [ -n "$awk_file" ] ; then
tmp_file=$(mktemp)
$delhashbang "$awk_file" | \
- eval '$prepro $incopt"$(dirname "$awk_file")" '"$prepro_opts -" | \
+ eval "$prepro $incopt"'"$(dirname "$awk_file")" '"$prepro_opts -" | \
collapse > $tmp_file
[ $prepro_only ] \
&& cat $tmp_file \
@@ -181,10 +168,10 @@ elif [ $# -gt 0 ] ; then
tmp_file=$(mktemp)
if [ $prepro_only ] ; then
printf "%s" "$1" | $delhashbang | \
- eval '$prepro $incopt"$(pwd)" '"$prepro_opts - | collapse"
+ eval "$prepro $incopt"$(pwd)" $prepro_opts - | collapse"
else
printf "%s" "$1" | $delhashbang | \
- eval '$prepro $incopt"$(pwd)" '"$prepro_opts - | collapse" > $tmp_file
+ eval "$prepro $incopt"$(pwd)" $prepro_opts - | collapse" > $tmp_file
shift
eval "$awk $awk_opts -f $tmp_file -- \"\$@\""
fi
diff --git a/testawk b/testawk
new file mode 100755
index 0000000..a41b4b6
--- /dev/null
+++ b/testawk
@@ -0,0 +1,3 @@
+#!/bin/sh
+printf "[%.2s]" "$@"
+printf "\n"
diff --git a/testcases b/testcases
index 8758398..31bf6af 100644
--- a/testcases
+++ b/testcases
@@ -180,14 +180,14 @@ foo_bar
foo_bar
--
32:
-./cppawk --awk='printf "[%.2s]"' foo
+./cppawk --awk=./testawk foo
:
[-f][/t][--]
--
33:
-./cppawk --prepro-only --prepro='printf %.3s' abc
+./cppawk --prepro-only --prepro=./testcpp abc
:
--iq-D_-I.-
+[-iq][-D_][-I.][-]
--
34:
./cppawk --prepro-only --awk=mawk mawk=__mawk__ | grep mawk
diff --git a/testcpp b/testcpp
new file mode 100755
index 0000000..d93bcbb
--- /dev/null
+++ b/testcpp
@@ -0,0 +1,3 @@
+#!/bin/sh
+printf "[%.3s]" "$@"
+printf "\n"