Skip to content

Commit 7ece381

Browse files
rfvirgilshuahkh
authored andcommitted
kunit: Protect string comparisons against NULL
Add NULL checks to KUNIT_BINARY_STR_ASSERTION() so that it will fail cleanly if either pointer is NULL, instead of causing a NULL pointer dereference in the strcmp(). A test failure could be that a string is unexpectedly NULL. This could be trapped by KUNIT_ASSERT_NOT_NULL() but that would terminate the test at that point. It's preferable that the KUNIT_EXPECT_STR*() macros can handle NULL pointers as a failure. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Reviewed-by: David Gow <davidgow@google.com> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 5fb1a8c commit 7ece381

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

include/kunit/test.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ do { \
758758
.right_text = #right, \
759759
}; \
760760
\
761-
if (likely(strcmp(__left, __right) op 0)) \
761+
if (likely((__left) && (__right) && (strcmp(__left, __right) op 0))) \
762762
break; \
763763
\
764764
\

0 commit comments

Comments
 (0)