summaryrefslogtreecommitdiff
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
authorGregory Bean <gbean@codeaurora.org>2011-05-10 12:34:09 -0700
committerDavid Keitel <dkeitel@codeaurora.org>2016-03-23 20:51:44 -0700
commitcf032648ebdf301b5c365e0852abf29c654b72da (patch)
tree4ea9bf9b68d2632e9fb5312f24c7ea236a5d3ea8 /scripts/checkpatch.pl
parent05379004cc48c1d9a2b2fd6ff4e518bd92355062 (diff)
checkpatch: deprecate unbounded string functions.
Unbounded string functions are overflow risks. The 'n' versions of those functions should be used instead. Change-Id: Ice0fb3ebdae9aa88cc7e764ffdf68cbed857febf Signed-off-by: Gregory Bean <gbean@codeaurora.org> (cherry picked from commit 15e1e97d66dd6a6039c1ec2bd549a632fe361128) Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl20
1 files changed, 20 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f59113732720..b1a2511de9b8 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4950,6 +4950,26 @@ sub process {
$herecurr);
}
+# unbounded string functions are overflow risks
+ my %str_fns = (
+ "sprintf" => "snprintf",
+ "strcpy" => "strlcpy",
+ "strncpy" => "strlcpy",
+ "strcat" => "strlcat",
+ "strncat" => "strlcat",
+ "vsprintf" => "vsnprintf",
+ "strchr" => "strnchr",
+ "strstr" => "strnstr",
+ );
+ foreach my $k (keys %str_fns) {
+ if ($line =~ /\b$k\b/) {
+ ERROR("UNBOUNDED_STRING_FNS",
+ "Use of $k is deprecated: " .
+ "use $str_fns{$k} instead.\n" .
+ $herecurr);
+ }
+ }
+
# warn about #if 0
if ($line =~ /^.\s*\#\s*if\s+0\b/) {
WARN("IF_0",