Skip to contentSkip to conversation

selftests: ktap_helpers: Fix uninitialized variable

PATCH In review Mickaël Salaün 1 participant 2 messages Nov 27, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: ktap_helpers: Fix uninitialized variable

__ktap_test() may be called without the optional third argument which is an issue for scripts using set -u to detect uninitialized variables and potential bugs.

Fix this optional "directive" argument by either using the third argument or an empty string.

This was discovered while developing tests for script control execution:
https://lore.kernel.org/r/[email protected]

Cc Kees Cook <[email protected]>
Cc Nícolas F. R. A. Prado <[email protected]>
Cc Shuah Khan <[email protected]>
---
 tools/testing/selftests/kselftest/ktap_helpers.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kselftest/ktap_helpers.sh +1 -1
index 79a125eb24c2..14e7f3ec3f84 100644
@@ -40,7 +40,7 @@ ktap_skip_all() {
 __ktap_test() {
 	result="$1"
 	description="$2"
-	directive="$3" # optional
+	directive="${3:-}" # optional
 
 	local directive_str=
 	[ ! -z "$directive" ] && directive_str="# $directive"
Signature · 1 line
2.47.1
#1 lore raw
Quoted 7 lines · Mickaël Salaün

__ktap_test() may be called without the optional third argument which is an issue for scripts using set -u to detect uninitialized variables and potential bugs.

Fix this optional "directive" argument by either using the third argument or an empty string.

Quoted 6 lines

This was discovered while developing tests for script control execution:
https://lore.kernel.org/r/[email protected]

Cc Kees Cook <[email protected]>
Cc Nícolas F. R. A. Prado <[email protected]>
Cc Shuah Khan <[email protected]>

Please add this missing tag:

Fixes 14571ab1ad21 ("kselftest: Add new test for detecting unprobed Devicetree devices")
Quoted 22 lines
---
 tools/testing/selftests/kselftest/ktap_helpers.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kselftest/ktap_helpers.sh +1 -1
index 79a125eb24c2..14e7f3ec3f84 100644
@@ -40,7 +40,7 @@ ktap_skip_all() {
 __ktap_test() {
 	result="$1"
 	description="$2"
-	directive="$3" # optional
+	directive="${3:-}" # optional
 
 	local directive_str=
 	[ ! -z "$directive" ] && directive_str="# $directive"
Signature · 1 line
2.47.1