]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
checksrc: catch banned functions when preceded by `(`
authorViktor Szakats <commit@vsz.me>
Tue, 30 Sep 2025 10:47:01 +0000 (12:47 +0200)
committerViktor Szakats <commit@vsz.me>
Tue, 30 Sep 2025 11:16:47 +0000 (13:16 +0200)
Also add a test case.

Closes #18779

scripts/checksrc.pl
tests/data/test1185

index 23c9ef530107ee70224352f372747e632368efbd..5e8434d5fabfc6ca74d21945b1edd15f22748fcb 100755 (executable)
@@ -893,7 +893,8 @@ sub scanfile {
         # scan for use of banned functions
         my $bl = $l;
       again:
-        if(($l =~ /^(.*?\W)(\w+)(\s*\()/x) && $banfunc{$2}) {
+        if((($l =~ /^(.*?\W)(\w+)(\s*\()/x) && $banfunc{$2}) ||
+           (($l =~ /^(.*?\()(\w+)(\s*\()/x) && $banfunc{$2})) {
             my $bad = $2;
             my $prefix = $1;
             my $suff = $3;
@@ -904,6 +905,7 @@ sub scanfile {
             $prefix =~ s/\*/\\*/;
             $prefix =~ s/\[/\\[/;
             $prefix =~ s/\]/\\]/;
+            $prefix =~ s/\(/\\(/;
             $suff =~ s/\(/\\(/;
             $l =~ s/$prefix$bad$suff/$prefix$replace/;
             goto again;
index 43a27f087054f960f1a23e6f8cb48d361f6f7ed9..14a23dc01ac95c02de705953f97db3f3a9c2ccbd 100644 (file)
@@ -74,6 +74,8 @@ void startfunc(int a, int b) {
 
  if(a) b++;
 
+ if(sprintf(buffer, "%s", moo)) {}
+
  // CPP comment ?
 
  /* comment doesn't end
@@ -192,7 +194,10 @@ void startfunc(int a, int b) {
 ./%LOGDIR/code1185.c:57:7: warning: conditional block on the same line (ONELINECONDITION)
   if(a) b++;
        ^
-./%LOGDIR/code1185.c:59:2: warning: // comment (CPPCOMMENTS)
+./%LOGDIR/code1185.c:59:5: warning: use of sprintf is banned (BANNEDFUNC)
+  if(sprintf(buffer, "%s", moo)) {}
+     ^
+./%LOGDIR/code1185.c:61:2: warning: // comment (CPPCOMMENTS)
   // CPP comment ?
   ^
 ./%LOGDIR/code1185.c:1:1: error: Missing copyright statement (COPYRIGHT)
@@ -201,7 +206,7 @@ void startfunc(int a, int b) {
 ./%LOGDIR/code1185.c:1:1: error: Missing closing comment (OPENCOMMENT)
  
  ^
-checksrc: 0 errors and 39 warnings
+checksrc: 0 errors and 40 warnings
 </stdout>
 <errorcode>
 5