Skip to content

Commit ae1a863

Browse files
committed
kunit/fortify: Fix memcmp() test to be amplitude agnostic
When memcmp() returns a non-zero value, only the signed bit has any meaning. The actual value may differ between implementations. Reported-by: Nathan Chancellor <[email protected]> Closes: ClangBuiltLinux#2025 Tested-by: Nathan Chancellor <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 890a648 commit ae1a863

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/fortify_kunit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ static void fortify_test_memcmp(struct kunit *test)
990990
KUNIT_ASSERT_EQ(test, memcmp(one, two, one_len), 0);
991991
KUNIT_EXPECT_EQ(test, fortify_read_overflows, 0);
992992
/* Still in bounds, but no longer matching. */
993-
KUNIT_ASSERT_EQ(test, memcmp(one, two, one_len + 1), -32);
993+
KUNIT_ASSERT_LT(test, memcmp(one, two, one_len + 1), 0);
994994
KUNIT_EXPECT_EQ(test, fortify_read_overflows, 0);
995995

996996
/* Catch too-large ranges. */

0 commit comments

Comments
 (0)