]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
view: fix addr2url mapping corruption
authorEric Wong <e@80x24.org>
Fri, 6 Sep 2024 23:29:03 +0000 (23:29 +0000)
committerEric Wong <e@80x24.org>
Sat, 7 Sep 2024 00:06:59 +0000 (00:06 +0000)
We must avoid generating a qr/\b()\b/ regexp which matches
every word boundary.  This is caused by a particular set of
circumstances for WWW instances:

1. extindex must be in use
2. cindex must NOT be in use OR WWW->preload wasn't used
   (custom .psgi or non-p-i-{httpd,netd} users)
3. first HTTP request hits /$EXTINDEX/$MSGID/
   (where $EXTINDEX is typically `all')

On extindex-using instances without a cindex configured, the
first HTTP request hitting the extindex encounters an empty
{-by_addr} hash table.  This empty {-by_addr} hash table causes
View->addr2urlmap() to return an all-matching regexp which
corrupts HTML when attempting address substitutions.

cindex-using instances avoid the problem by triggering
_fill_all() during PublicInbox::WWW->preload and ensuring
{-by_addr} of the PublicInbox::Config object is populated.

Thanks to Konstantin for the initial report and Filip for the
immensely helpful explanation of the problem.

Helped-by: Filip Hejsek <filip.hejsek@gmail.com>
Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20240903-brainy-lionfish-of-saturation-71ae1a@lemur/
Fixes: 48cbe0c3c8dc4d26 (www: linkify inbox addresses in To/Cc headers, 2024-01-09)
lib/PublicInbox/View.pm

index bc093a20180bfbaf1555fa3bb8f24bf7dfca4470..154e75379c3d6f7401b510bc0bf592c99ccb8c8e 100644 (file)
@@ -203,8 +203,12 @@ sub addr2urlmap ($) {
                my $tmp = $ctx->{www}->{pi_cfg}->{-addr2urlmap};
                my @k = keys %$tmp; # random order
                delete @$tmp{@k[0..3]} if scalar(@k) > 7;
-               my $re = join('|', map { quotemeta } keys %addr2url);
-               $tmp->{$key} = [ qr/\b($re)\b/i, \%addr2url ];
+               if (scalar keys %addr2url) {
+                       my $re = join('|', map { quotemeta } keys %addr2url);
+                       $tmp->{$key} = [ qr/\b($re)\b/i, \%addr2url ];
+               } else { # nothing? NUL should never match:
+                       [ qr/(\0)/, { "\0" => './' } ];
+               }
        };
        @$ent;
 }