Skip to content

Commit d0f9084

Browse files
committed
checkpatch: Check for strcpy and strncpy too
Warn about strcpy(), strncpy(), and strlcpy(). Suggest strscpy() and include pointers to the open KSPP issues for each, which has further details and replacement procedures. Cc: Andy Whitcroft <[email protected]> Cc: Joe Perches <[email protected]> Cc: Dwaipayan Ray <[email protected]> Cc: Lukas Bulwahn <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d0c2d66 commit d0f9084

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

scripts/checkpatch.pl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6997,10 +6997,22 @@ sub process {
69976997
# }
69986998
# }
69996999

7000+
# strcpy uses that should likely be strscpy
7001+
if ($line =~ /\bstrcpy\s*\(/) {
7002+
WARN("STRCPY",
7003+
"Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr);
7004+
}
7005+
70007006
# strlcpy uses that should likely be strscpy
70017007
if ($line =~ /\bstrlcpy\s*\(/) {
70027008
WARN("STRLCPY",
7003-
"Prefer strscpy over strlcpy - see: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw\@mail.gmail.com/\n" . $herecurr);
7009+
"Prefer strscpy over strlcpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr);
7010+
}
7011+
7012+
# strncpy uses that should likely be strscpy or strscpy_pad
7013+
if ($line =~ /\bstrncpy\s*\(/) {
7014+
WARN("STRNCPY",
7015+
"Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr);
70047016
}
70057017

70067018
# typecasts on min/max could be min_t/max_t

0 commit comments

Comments
 (0)