From: Quentin Young Date: Wed, 8 May 2019 15:46:29 +0000 (+0000) Subject: tools: add lints for unsafe functions X-Git-Tag: base_7.2~374^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=5307949e8fdc6970dc401e67392db642639f3a4c;p=matthieu%2Ffrr.git tools: add lints for unsafe functions Signed-off-by: Quentin Young --- diff --git a/tools/checkpatch.pl b/tools/checkpatch.pl index 77e6e9a330..1b48d10a09 100755 --- a/tools/checkpatch.pl +++ b/tools/checkpatch.pl @@ -6347,6 +6347,35 @@ sub process { "Please, only use 32 bit atomics.\n" . $herecurr); } +# check for use of strcpy() + if ($line =~ /\bstrcpy\s*\(.*\)/) { + ERROR("STRCPY", + "strcpy() is error-prone; please use strlcpy()" . $herecurr); + } + +# check for use of strncpy() + if ($line =~ /\bstrncpy\s*\(.*\)/) { + WARN("STRNCPY", + "strncpy() is error-prone; please use strlcpy() if possible, or memcpy()" . $herecurr); + } + +# check for use of strcat() + if ($line =~ /\bstrcat\s*\(.*\)/) { + ERROR("STRCAT", + "strcat() is error-prone; please use strlcat() if possible" . $herecurr); + } + +# check for use of strncat() + if ($line =~ /\bstrncat\s*\(.*\)/) { + WARN("STRNCAT", + "strncat() is error-prone; please use strlcat() if possible" . $herecurr); + } + +# check for use of bzero() + if ($line =~ /\bbzero\s*\(.*\)/) { + ERROR("BZERO", + "bzero() is deprecated; use memset()" . $herecurr); + } } # If we have no input at all, then there is nothing to report on