selftests:breakpoints: Fix Format String Warning in breakpoint_test
PATCH 1/1 selftests:breakpoints: Fix Format String Warning in breakpoint_test
From: angquan yu <[email protected]>
This commit resolves a compiler warning regardingthe use of non-literal format strings in breakpoint_test.c.
The functions ksft_test_result_pass and ksft_test_result_fail were previously called with a variable msg directly, which could potentially lead to format string vulnerabilities.
Changes made:
- Modified the calls to ksft_test_result_pass and ksft_test_result_fail by adding a "%s" format specifier. This explicitly declares msg as a string argument, adhering to safer coding practices and resolving the compiler warning.
This change does not affect the functional behavior of the code but ensures better code safety and compliance with recommended C programming standards.
The previous warning is "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);
| "--- tools/testing/selftests/breakpoints/breakpoint_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/breakpoints/breakpoint_test.c +2 -2
@@ -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" , msg);else -ksft_test_result_fail (msg); +ksft_test_result_fail ("%s" , msg); }static void launch_instruction_breakpoints (char *buf,int local,int global)
Signature · 1 line
2.39.2
Shuah Khan
maintainerQuoted 21 lines · angquan yu
From: angquan yu <[email protected]>
This commit resolves a compiler warning regardingthe use of non-literal format strings in
breakpoint_test.c.The functions
ksft_test_result_passandksft_test_result_failwere previously called with a variablemsgdirectly, which could potentially lead to format string vulnerabilities.Changes made:
- Modified the calls toksft_test_result_passandksft_test_result_failby adding a "%s" format specifier. This explicitly declaresmsgas a string argument, adhering to safer coding practices and resolving the compiler warning.This change does not affect the functional behavior of the code but ensures better code safety and compliance with recommended C programming standards.
The previous warning is "breakpoint_test.c:287:17:
warning: format not a string literal and no format arguments [-Wformat-security]
Quoted 8 lines
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); | "Signed-off-by angquan yu <[email protected]>
Thank you foe the fix. Applied to linux-kselftest next Linux 6.8-rc1
thanks,
-- Shuah