2024-01-09 21:54:45

by Mirsad Todorovac

[permalink] [raw]
Subject: [PATCH v1 0/2] selftest: breakpoints: minor format string fixes

Minor consistency fixes.

They clear a couple of compiler format string warnings.

[1/2] is the fix of an obvious typo in the format specifier
[2/2] is securing the print function against spurious format specifiers
in passed paramater string

Mirsad Todorovac (2):
selftest: breakpoints: fix a minor typo in the format string
selftest: breakpoints: clear the format string warning and secure the
output

tools/testing/selftests/breakpoints/breakpoint_test.c | 4 ++--
tools/testing/selftests/breakpoints/step_after_suspend_test.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

--
2.40.1



2024-01-09 21:55:16

by Mirsad Todorovac

[permalink] [raw]
Subject: [PATCH v1 1/2] selftest: breakpoints: fix a minor typo in the format string

GCC 13.2.0 reported a format string warning:

step_after_suspend_test.c: In function ‘run_test’:
step_after_suspend_test.c:92:32: warning: too many arguments for format [-Wformat-extra-args]
92 | ksft_print_msg("waitpid() failed: $s\n", strerror(errno));
| ^~~~~~~~~~~~~~~~~~~~~~~~

Fixing the typo $s into %s resolves the issue.

Fixes: 3fa72f2c784b5 ("selftests: breakpoints: step_after_suspend_test use ksft_* var arg msg api")
Cc: Shuah Khan <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Mirsad Todorovac <[email protected]>
---
tools/testing/selftests/breakpoints/step_after_suspend_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/breakpoints/step_after_suspend_test.c b/tools/testing/selftests/breakpoints/step_after_suspend_test.c
index 2cf6f10ab7c4..b8703c499d28 100644
--- a/tools/testing/selftests/breakpoints/step_after_suspend_test.c
+++ b/tools/testing/selftests/breakpoints/step_after_suspend_test.c
@@ -89,7 +89,7 @@ int run_test(int cpu)

wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) {
- ksft_print_msg("waitpid() failed: $s\n", strerror(errno));
+ ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
return KSFT_FAIL;
}
if (WIFEXITED(status)) {
--
2.40.1


2024-01-09 21:55:48

by Mirsad Todorovac

[permalink] [raw]
Subject: [PATCH v1 2/2] selftest: breakpoints: clear the format string warning and secure the output

GCC 13.2.0 compiler reported the following warning:

breakpoint_test.c: In function ‘check_success’:
breakpoint_test.c:287:17: warning: format not a string literal and no format arguments [-Wformat-security]
287 | ksft_test_result_pass(msg);
| ^~~~~~~~~~~~~~~~~~~~~
breakpoint_test.c:289:17: warning: format not a string literal and no format arguments [-Wformat-security]
289 | ksft_test_result_fail(msg);
| ^~~~~~~~~~~~~~~~~~~~~

ksft_*() functions are unprotected against potential spurious format specifiers
in msg.

Protecting the conversion with "%s\n" format string fixes the warning.

Fixes: 748e84b79af01 ("kselftest: breakpoints: convert breakpoint_test to TAP13 output")
Cc: Paul Elder <[email protected]>
Cc: Alice Ferrazzi <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Shuah Khan <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Mirsad Todorovac <[email protected]>
---
tools/testing/selftests/breakpoints/breakpoint_test.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/breakpoints/breakpoint_test.c b/tools/testing/selftests/breakpoints/breakpoint_test.c
index 3266cc9293fe..07249251859b 100644
--- a/tools/testing/selftests/breakpoints/breakpoint_test.c
+++ b/tools/testing/selftests/breakpoints/breakpoint_test.c
@@ -284,9 +284,9 @@ static void check_success(const char *msg)
nr_tests++;

if (ret)
- ksft_test_result_pass(msg);
+ ksft_test_result_pass("%s\n", msg);
else
- ksft_test_result_fail(msg);
+ ksft_test_result_fail("%s\n", msg);
}

static void launch_instruction_breakpoints(char *buf, int local, int global)
--
2.40.1