ARM: s3c: Use strscpy to replace strlcpy
Subsystems (3)
PATCH 1/1 ARM: s3c: Use strscpy to replace strlcpy
The strlcpy should not be used because it doesn't limit the source length. As linus says, it's a completely useless function if you can't implicitly trust the source string - but that is almost always why people think they should use it! All in all the BSD function will lead some potential bugs.
But the strscpy doesn't require reading memory from the src string beyond the specified "count" bytes, and since the return value is easier to error-check than strlcpy()'s. In addition, the implementation is robust to the string changing out from underneath it, unlike the current strlcpy() implementation.
Thus, We prefer using strscpy instead of strlcpy.
--- arch/arm/mach-s3c/mach-mini6410.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-s3c/mach-mini6410.c +1 -1
@@ -262,7 +262,7 @@ static char mini6410_features_str[12] __initdata = "0";static int __init mini6410_features_setup (char *str) {if (str) -strlcpy (mini6410_features_str, str, +strscpy (mini6410_features_str, str,sizeof (mini6410_features_str));return 1 ; }
Signature · 1 line
2.33.0
Quoted 6 lines · Jason Wang
The strlcpy should not be used because it doesn't limit the source length. As linus says, it's a completely useless function if you can't implicitly trust the source string - but that is almost always why people think they should use it! All in all the BSD function will lead some potential bugs.
Quoted 7 lines
But the strscpy doesn't require reading memory from the src string beyond the specified "count" bytes, and since the return value is easier to error-check than strlcpy()'s. In addition, the implementation is robust to the string changing out from underneath it, unlike the current
strlcpy()implementation.Thus, We prefer using strscpy instead of strlcpy.
Don't copy-paste kernel documentation into commits. It's enough to say that strlcpy is preferred, according to the kernel coding style (see strlcpy()).
If you want to add more sentences, make them relevant, e.g. describe possible effect of bugs depending on the source.
Best regards,
Krzysztof
Krzysztof Kozlowski
AppliedQuoted 6 lines · Jason Wang
The strlcpy should not be used because it doesn't limit the source length. As linus says, it's a completely useless function if you can't implicitly trust the source string - but that is almost always why people think they should use it! All in all the BSD function will lead some potential bugs.
Quoted 7 lines
But the strscpy doesn't require reading memory from the src string beyond the specified "count" bytes, and since the return value is easier to error-check than strlcpy()'s. In addition, the implementation is robust to the string changing out from underneath it, unlike the current
strlcpy()implementation.[...]
Applied, thanks!
[1/1] ARM: s3c: Use strscpy to replace strlcpy
commit: aa519471715ce73034ffaa52fc85681de31c1acf
Best regards,
Signature · 1 line
Krzysztof Kozlowski <[email protected]>