public inbox for linux-kselftest@vger.kernel.org
 help / color / mirror / Atom feed
From: Fernando Fernandez Mancera <fmancera@suse.de>
To: linux-kselftest@vger.kernel.org
Cc: shuah@kernel.org, Fernando Fernandez Mancera <fmancera@suse.de>
Subject: [PATCH] selftests/run_kselftest.sh: fix infinite loop on missing argument
Date: Mon, 13 Apr 2026 16:03:07 +0200	[thread overview]
Message-ID: <20260413140307.4178-1-fmancera@suse.de> (raw)

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.

Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
---
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(+)

diff --git a/tools/testing/selftests/run_kselftest.sh b/tools/testing/selftests/run_kselftest.sh
index 84d45254675c..2755c6aa367b 100755
--- a/tools/testing/selftests/run_kselftest.sh
+++ b/tools/testing/selftests/run_kselftest.sh
@@ -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)
-- 
2.53.0


                 reply	other threads:[~2026-04-13 14:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260413140307.4178-1-fmancera@suse.de \
    --to=fmancera@suse.de \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox