diff mbox series

[v1] selftests: ktap_helpers: Fix uninitialized variable

Message ID 20241127160342.31472-1-mic@digikod.net (mailing list archive)
State New
Headers show
Series [v1] selftests: ktap_helpers: Fix uninitialized variable | expand

Commit Message

Mickaël Salaün Nov. 27, 2024, 4:03 p.m. UTC
__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/20241112191858.162021-7-mic@digikod.net

Cc: Kees Cook <kees@kernel.org>
Cc: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Cc: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Mickaël Salaün <mic@digikod.net>
---
 tools/testing/selftests/kselftest/ktap_helpers.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Mickaël Salaün Nov. 27, 2024, 4:06 p.m. UTC | #1
On Wed, Nov 27, 2024 at 05:03:40PM +0100, Mickaël Salaün wrote:
> __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/20241112191858.162021-7-mic@digikod.net
> 
> Cc: Kees Cook <kees@kernel.org>
> Cc: Nícolas F. R. A. Prado <nfraprado@collabora.com>
> Cc: Shuah Khan <skhan@linuxfoundation.org>

Please add this missing tag:

Fixes: 14571ab1ad21 ("kselftest: Add new test for detecting unprobed Devicetree devices")

> Signed-off-by: Mickaël Salaün <mic@digikod.net>
> ---
>  tools/testing/selftests/kselftest/ktap_helpers.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/kselftest/ktap_helpers.sh b/tools/testing/selftests/kselftest/ktap_helpers.sh
> index 79a125eb24c2..14e7f3ec3f84 100644
> --- a/tools/testing/selftests/kselftest/ktap_helpers.sh
> +++ b/tools/testing/selftests/kselftest/ktap_helpers.sh
> @@ -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"
> -- 
> 2.47.1
> 
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/kselftest/ktap_helpers.sh b/tools/testing/selftests/kselftest/ktap_helpers.sh
index 79a125eb24c2..14e7f3ec3f84 100644
--- a/tools/testing/selftests/kselftest/ktap_helpers.sh
+++ b/tools/testing/selftests/kselftest/ktap_helpers.sh
@@ -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"