Commit ae1a863b authored by Kees Cook's avatar Kees Cook
Browse files

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: default avatarNathan Chancellor <nathan@kernel.org>
Closes: https://github.com/ClangBuiltLinux/linux/issues/2025


Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/r/20240518184020.work.604-kees@kernel.org


Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent 890a6481
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -990,7 +990,7 @@ static void fortify_test_memcmp(struct kunit *test)
	KUNIT_ASSERT_EQ(test, memcmp(one, two, one_len), 0);
	KUNIT_EXPECT_EQ(test, fortify_read_overflows, 0);
	/* Still in bounds, but no longer matching. */
	KUNIT_ASSERT_EQ(test, memcmp(one, two, one_len + 1), -32);
	KUNIT_ASSERT_LT(test, memcmp(one, two, one_len + 1), 0);
	KUNIT_EXPECT_EQ(test, fortify_read_overflows, 0);

	/* Catch too-large ranges. */