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 <nathan@kernel.org> Closes: ClangBuiltLinux#2025 Tested-by: Nathan Chancellor <nathan@kernel.org> Link: https://lore.kernel.org/r/20240518184020.work.604-kees@kernel.org Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent 890a648 commit ae1a863

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

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)