git » libfiu » commit a417ce4

fiu-run: Fix shell error in deprecated option parsing

author Alberto Bertogli
2023-02-25 11:14:02 UTC
committer Alberto Bertogli
2023-02-26 10:24:03 UTC
parent 5dcc6d449dc86d4ba9abc99ac52fd5798e573738

fiu-run: Fix shell error in deprecated option parsing

When using the deprecated options (e.g. `-e`), there is a bug where some
of the bash comparisons are invalid because the variable names are
incorrect.

This bug has been present since these flags were deprecated in 2012
(commit c5f4c471).

Thanks to Lynn Kerby <lfkerby@gmail.com> who reported this issue
and provided a patch for it!

Co-authored-by: Lynn Kerby <lfkerby@gmail.com>

preload/run/fiu-run.in +3 -3
tests/utils/test-basic_run.sh +5 -1

diff --git a/preload/run/fiu-run.in b/preload/run/fiu-run.in
index 8926094..ecd69f2 100644
--- a/preload/run/fiu-run.in
+++ b/preload/run/fiu-run.in
@@ -83,13 +83,13 @@ function opts_reset() {
 }
 
 function add_deprecated_enable() {
-	if [ "$NAME" == "" ]; then
+	if [ "$DEP_NAME" == "" ]; then
 		return
 	fi;
 
 	PARAMS="name=$DEP_NAME,failnum=$DEP_FAILNUM,failinfo=$DEP_FAILINFO"
-	if [ $PROB -ge 0 ]; then
-		C="enable_random $PARAMS,probability=$PROB"
+	if [ "$DEP_PROB" -ge 0 ]; then
+		C="enable_random $PARAMS,probability=$DEP_PROB"
 	else
 		C="enable $PARAMS"
 	fi
diff --git a/tests/utils/test-basic_run.sh b/tests/utils/test-basic_run.sh
index 4d2ba60..75e3075 100755
--- a/tests/utils/test-basic_run.sh
+++ b/tests/utils/test-basic_run.sh
@@ -12,6 +12,10 @@ set -ex
 ./wrap fiu-run -c "enable name=p1" true
 
 # open() failure.
-! ./wrap fiu-run -x -c "enable name=posix/io/oc/open" cat /dev/null
+( ! ./wrap fiu-run -x -c "enable name=posix/io/oc/open" cat /dev/null )
 
+# Deprecated option: -e.
+( ! ./wrap fiu-run -x -e "posix/io/oc/open" cat /dev/null )
 
+# Deprecated option: -p.
+( ! ./wrap fiu-run -x -e "posix/io/oc/open" -p 1 cat /dev/null )