Skip to contentSkip to conversation

selftests/run_kselftest.sh: fix infinite loop on missing argument

PATCH New Fernando Fernandez Mancera 1 participant 1 message Apr 13 Kselftest

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/run_kselftest.sh: fix infinite loop on missing argument

Currently, passing an option that requires an argument as the final parameter without providing the actual argument causes the script to enter an infinite loop.

Handle this by adding a proper check for the number of positional parameters.

---
Note: I hit this while automating some testing, I wasted a couple of hours of CPU cycles + energy

---
 tools/testing/selftests/run_kselftest.sh | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
tools/testing/selftests/run_kselftest.sh +16 -0
index 84d45254675c..2755c6aa367b 100755
@@ -58,12 +58,24 @@ while true; do
 			per_test_logging=1
 			shift ;;
 		-t | --test)
+			if [ $# -lt 2 ]; then
+				echo "Error: option '$1' requires an argument" >&2
+				usage 1
+			fi
 			TESTS="$TESTS $2"
 			shift 2 ;;
 		-S | --skip)
+			if [ $# -lt 2 ]; then
+				echo "Error: option '$1' requires an argument" >&2
+				usage 1
+			fi
 			SKIP="$SKIP $2"
 			shift 2 ;;
 		-c | --collection)
+			if [ $# -lt 2 ]; then
+				echo "Error: option '$1' requires an argument" >&2
+				usage 1
+			fi
 			COLLECTIONS="$COLLECTIONS $2"
 			shift 2 ;;
 		-l | --list)
@@ -79,6 +91,10 @@ while true; do
 			RUN_IN_NETNS=1
 			shift ;;
 		-o | --override-timeout)
+			if [ $# -lt 2 ]; then
+				echo "Error: option '$1' requires an argument" >&2
+				usage 1
+			fi
 			kselftest_override_timeout="$2"
 			shift 2 ;;
 		-h | --help)
Signature · 1 line
2.53.0