mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-29 05:12:59 +01:00
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 <[email protected]> Reviewed-by: David Gow <[email protected]> Reviewed-by: Muhammad Usama Anjum <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
This commit is contained in:
1 parent
5fb1a8c671
commit
7ece381aa7
1 file changed
+1
-1
@@ -758,7 +758,7 @@ do { \
|
||||
.right_text = #right, \
|
||||
}; \
|
||||
\
|
||||
if (likely(strcmp(__left, __right) op 0)) \
|
||||
if (likely((__left) && (__right) && (strcmp(__left, __right) op 0))) \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
|
||||
Reference in new issue
Block a user