checkpatch: Added warnings in favor of strscpy().
Subsystems (3)
PATCH v2 1/1 checkpatch: Added warnings in favor of strscpy().
Added warnings in checkpatch.pl script to :
1. Deprecate strcpy() in favor of strscpy().
2. Deprecate strlcpy() in favor of strscpy().
3. Deprecate strncpy() in favor of strscpy() or strscpy_pad().
Updated strncpy() section in Documentation/process/deprecated.rst to cover strscpy_pad() case.
--- Documentation/process/deprecated.rst | 6 +++--- scripts/checkpatch.pl | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-)
Documentation/process/deprecated.rst +3 -3
@@ -93,9 +93,9 @@ will be NUL terminated. This can lead to various linear read overflows and other misbehavior due to the missing termination. It also NUL-pads the destination buffer if the source contents are shorter than the destination buffer size, which may be a needless performance penalty for callers using -only NUL-terminated strings. The safe replacement is :c:func:`strscpy`. -(Users of :c:func:`strscpy` still needing NUL-padding will need an -explicit :c:func:`memset` added.) +only NUL-terminated strings. In this case, the safe replacement is +:c:func:`strscpy`. If, however, the destination buffer still needs +NUL-padding, the safe replacement is :c:func:`strscpy_pad`. If a caller is using non-NUL-terminated strings, :c:func:`strncpy()` can still be used, but destinations should be marked with the `__nonstring
scripts/checkpatch.pl +0 -0
@@ -595,6 +595,10 @@ our %deprecated_apis = (
"rcu_barrier_sched" => "rcu_barrier",
"get_state_synchronize_sched" => "get_state_synchronize_rcu",
"cond_synchronize_sched" => "cond_synchronize_rcu",
+ "strcpy" => "strscpy",
+ "strlcpy" => "strscpy",
+ "strncpy" => "strscpy, strscpy_pad or for non-NUL-terminated strings,
+ strncpy() can still be used, but destinations should be marked with the __nonstring",
);
#Create a search pattern for all these strings to speed up a loop below
--
2.7.4
Quoted 10 lines · Nitin Gote
Added warnings in checkpatch.pl script to :
1. Deprecate
strcpy()in favor ofstrscpy().
2. Deprecatestrlcpy()in favor ofstrscpy().
3. Deprecatestrncpy()in favor ofstrscpy()orstrscpy_pad().Updated
strncpy()section inDocumentation/process/deprecated.rstto coverstrscpy_pad()case.Signed-off-by Nitin Gote <[email protected]>
This looks good. I think you're ready for sending this upstream. Please see:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html
The To: should likely be:
Andrew Morton <[email protected]>
and I recommend CC to:
Jonathan Corbet <[email protected]>
Andy Whitcroft <[email protected]>
Joe Perches <[email protected]>
[email protected]
[email protected]
[email protected]
Thanks!
-Kees
Quoted 39 lines
--- Documentation/process/deprecated.rst | 6 +++--- scripts/checkpatch.pl | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-)Documentation/process/deprecated.rst +3
-3@@ -93,9 +93,9 @@ will be NUL terminated. This can lead to various linear read overflows and other misbehavior due to the missing termination. It also NUL-pads the destination buffer if the source contents are shorter than the destination buffer size, which may be a needless performance penalty for callers using -only NUL-terminated strings. The safe replacement is :c:func:`strscpy`. -(Users of :c:func:`strscpy` still needing NUL-padding will need an -explicit :c:func:`memset` added.) +only NUL-terminated strings. In this case, the safe replacement is +:c:func:`strscpy`. If, however, the destination buffer still needs +NUL-padding, the safe replacement is :c:func:`strscpy_pad`. If a caller is using non-NUL-terminated strings, :c:func:`strncpy()` can still be used, but destinations should be marked with the `__nonstringscripts/checkpatch.pl +4
-1@@ -595,6 +595,10 @@ our %deprecated_apis = ( "rcu_barrier_sched" => "rcu_barrier", "get_state_synchronize_sched" => "get_state_synchronize_rcu", "cond_synchronize_sched" => "cond_synchronize_rcu", + "strcpy" => "strscpy", + "strlcpy" => "strscpy", + "strncpy" => "strscpy, strscpy_pad or for non-NUL-terminated strings, + strncpy() can still be used, but destinations should be marked with the __nonstring", ); #Create a search pattern for all these strings to speed up a loop below --2.7.4
Signature · 1 line
Kees Cook