]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
util/fix-doc-nits: Fix link detection in collectnames() to be kinder
authorRichard Levitte <levitte@openssl.org>
Tue, 25 May 2021 08:29:24 +0000 (10:29 +0200)
committerRichard Levitte <levitte@openssl.org>
Wed, 26 May 2021 13:15:18 +0000 (15:15 +0200)
The way the links were parsed out of the contents caused a regexp
recursion.  The easiest way to deal with it is to find all markup
using $markup_re, and then parsing out the L markups and add them to
the links array.

Fixes #15449

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15450)

util/find-doc-nits

index c62307a9ce2222f7c17b26baa0752d115a38046e..7498ac6865a11b066c9e8549671b7b584f275d85 100755 (executable)
@@ -1000,16 +1000,27 @@ sub collectnames {
         }
     }
 
-    my @links =
-        $podinfo{contents} =~ /L<
-                              # if the link is of the form L<something|name(s)>,
-                              # then remove 'something'.  Note that 'something'
-                              # may contain POD codes as well...
-                              (?:(?:[^\|]|<[^>]*>)*\|)?
-                              # we're only interested in references that have
-                              # a one digit section number
-                              ([^\/>\(]+\(\d\))
-                             /gx;
+    my @links = ();
+    # Don't use this regexp directly on $podinfo{contents}, as it causes
+    # a regexp recursion, which fails on really big PODs.  Instead, use
+    # $markup_re to pick up general markup, and use this regexp to check
+    # that the markup that was found is indeed a link.
+    my $linkre = qr/L<
+                    # if the link is of the form L<something|name(s)>,
+                    # then remove 'something'.  Note that 'something'
+                    # may contain POD codes as well...
+                    (?:(?:[^\|]|<[^>]*>)*\|)?
+                    # we're only interested in references that have
+                    # a one digit section number
+                    ([^\/>\(]+\(\d\))
+                   /x;
+    while ( $podinfo{contents} =~ /$markup_re/msg ) {
+        my $x = $1;
+
+        if ($x =~ $linkre) {
+            push @links, $1;
+        }
+    }
     $link_map{$filename} = [ @links ];
 }