]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
checksrc: fix possible endless loops/errors in the banned function logic
authorViktor Szakats <commit@vsz.me>
Sat, 4 Oct 2025 11:04:29 +0000 (13:04 +0200)
committerViktor Szakats <commit@vsz.me>
Sat, 4 Oct 2025 15:49:21 +0000 (17:49 +0200)
By quoting the search expression to be replaced. This avoid the issue
when the code leading up to a banned function contained regex characters
that the script did not explicitly handle, e.g. `+`.

Assisted-by: Daniel Stenberg
Ref: https://perldoc.perl.org/functions/quotemeta
Follow-up to dd37d6970cfd8b4cf47ebd469f03772813b92c23 #18775

Closes #18845

scripts/checksrc.pl

index 637c0b7c8b5d11c0cc625376e77fb2195f2537fe..54800ce12d88758c3f16d991d6f7faa6f50876c3 100755 (executable)
@@ -907,14 +907,9 @@ sub scanfile {
             checkwarn("BANNEDFUNC",
                       $line, length($prefix), $file, $ol,
                       "use of $bad is banned");
-            my $replace = 'x' x (length($bad) + 1);
-            $prefix =~ s/\*/\\*/;
-            $prefix =~ s/\[/\\[/;
-            $prefix =~ s/\]/\\]/;
-            $prefix =~ s/\(/\\(/;
-            $prefix =~ s/\)/\\)/;
-            $suff =~ s/\(/\\(/;
-            $l =~ s/$prefix$bad$suff/$prefix$replace/;
+            my $search = quotemeta($prefix . $bad . $suff);
+            my $replace = $prefix . 'x' x (length($bad) + 1);
+            $l =~ s/$search/$replace/;
             goto again;
         }
         $l = $bl; # restore to pre-bannedfunc content