]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
checksrc: add STRNCPY as an opt-in rule to detect and error on strncpy
authorDaniel Stenberg <daniel@haxx.se>
Mon, 9 Sep 2024 08:15:49 +0000 (10:15 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 9 Sep 2024 11:47:50 +0000 (13:47 +0200)
make "lib/.checksrc" enable it

Closes #14830

lib/.checksrc
scripts/checksrc.pl

index 16133a44c56cb6d270799637123aaa7918a01c3c..9066946c890dd2d8a5a3fda9c82fbe2baeed8772 100644 (file)
@@ -1 +1,2 @@
 enable STRERROR
+enable STRNCPY
index 45897aad6f1beb565e765900274381f26ca86944..2316268dfde598381ae686b5ebdb0e618723b4d3 100755 (executable)
@@ -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.