From: Daniel Stenberg Date: Mon, 9 Sep 2024 08:15:49 +0000 (+0200) Subject: checksrc: add STRNCPY as an opt-in rule to detect and error on strncpy X-Git-Tag: curl-8_10_0~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80df6a5c12e51660ace2998cd717fa06d81ef0a9;p=thirdparty%2Fcurl.git checksrc: add STRNCPY as an opt-in rule to detect and error on strncpy make "lib/.checksrc" enable it Closes #14830 --- diff --git a/lib/.checksrc b/lib/.checksrc index 16133a44c5..9066946c89 100644 --- a/lib/.checksrc +++ b/lib/.checksrc @@ -1 +1,2 @@ enable STRERROR +enable STRNCPY diff --git a/scripts/checksrc.pl b/scripts/checksrc.pl index 45897aad6f..2316268dfd 100755 --- a/scripts/checksrc.pl +++ b/scripts/checksrc.pl @@ -50,6 +50,7 @@ my @ignore_line; my %warnings_extended = ( 'COPYRIGHTYEAR' => 'copyright year incorrect', 'STRERROR', => 'strerror() detected', + 'STRNCPY', => 'strncpy() detected', 'STDERR', => 'stderr detected', ); @@ -751,6 +752,18 @@ sub scanfile { } } } + if($warnings{"STRNCPY"}) { + # scan for use of banned strncpy. This is not a BANNEDFUNC to + # allow for individual enable/disable of this warning. + if($l =~ /^(.*\W)(strncpy)\s*\(/x) { + if($1 !~ /^ *\#/) { + # skip preprocessor lines + checkwarn("STRNCPY", + $line, length($1), $file, $ol, + "use of $2 is banned"); + } + } + } if($warnings{"STDERR"}) { # scan for use of banned stderr. This is not a BANNEDFUNC to # allow for individual enable/disable of this warning.