Commit Graph
2 Commits
Author SHA1 Message Date
Kees Cook 62e1cbfc5d fortify: Short-circuit known-safe calls to strscpy()
Replacing compile-time safe calls of strcpy()-related functions with
strscpy() was always calling the full strscpy() logic when a builtin
would be better. For example:

	char buf[16];
	strcpy(buf, "yes");

would reduce to __builtin_memcpy(buf, "yes", 4), but not if it was:

	strscpy(buf, yes, sizeof(buf));

Fix this by checking if all sizes are known at compile-time.

Cc: [email protected]
Tested-by: Nathan Chancellor <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
2022-11-01 10:04:52 -07:00
Kees Cook 41eefc46a3 string: Convert strscpy() self-test to KUnit
Convert the strscpy() self-test to a KUnit test.

Cc: David Gow <[email protected]>
Cc: Tobin C. Harding <[email protected]>
Tested-by: Nathan Chancellor <[email protected]>
Link: https://lore.kernel.org/lkml/Y072ZMk/[email protected]
Signed-off-by: Kees Cook <[email protected]>
2022-11-01 10:04:52 -07:00