From 80df6a5c12e51660ace2998cd717fa06d81ef0a9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 9 Sep 2024 10:15:49 +0200 Subject: [PATCH] checksrc: add STRNCPY as an opt-in rule to detect and error on strncpy make "lib/.checksrc" enable it Closes #14830 --- lib/.checksrc | 1 + scripts/checksrc.pl | 13 +++++++++++++ 2 files changed, 14 insertions(+) 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. -- 2.47.3