]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
searchview: fix uninitialized var on bogus `o='
authorEric Wong <e@80x24.org>
Thu, 30 Oct 2025 04:26:58 +0000 (04:26 +0000)
committerEric Wong <e@80x24.org>
Fri, 31 Oct 2025 00:31:15 +0000 (00:31 +0000)
When somebody enters an out-of-bounds `o=' (offset) query parameter
for a query which otherwise returns some results, we should avoid
triggering uninitialized variable warnings since we were unable
to extract min/max relevance percentages.  So just make up some
{min,max}_pct numbers for now if somebody tries that.

Aside from causing noise in stderr (often syslog), these were
otherwise harmless warning.  AFAIK, this could only be triggered
by someone entering URL parameters manually to view HTML, and
not in any generated URLs.

lib/PublicInbox/SearchView.pm

index 90a319cedf83cd785ee6a22656b8e1cbf0ecf91c..cc263e2b91efe2b92892c5cf6e3c79b47694a100 100644 (file)
@@ -247,32 +247,35 @@ sub search_nav_bot { # also used by WwwListing for searching extindex miscidx
        } else {
                $rv .= "No more results, only $total";
        }
-       my ($next, $join, $prev, $nd, $pd);
-
+       my ($next, $join, $prev, $nd, $pd, $min, $max);
+       if ($q->{r}) { # bogus % if somebody manually entered in OOB o=$OFFSET
+               $min = $q->{-min_pct} // 0;
+               $max = $q->{-max_pct} // 100;
+       }
        if ($o >= 0) { # sort descending
                my $n = $o + $l;
                if ($n < $total) {
                        $next = $q->qs_html(o => $n, l => $l);
-                       $nd = $q->{r} ? "[&lt;= $q->{-min_pct}%]" : '(older)';
+                       $nd = defined($min) ? "[&lt;= $min%]" : '(older)';
                }
                if ($o > 0) {
                        $join = $n < $total ? ' | ' : "\t";
                        my $p = $o - $l;
                        $prev = $q->qs_html(o => ($p > 0 ? $p : 0));
-                       $pd = $q->{r} ? "[&gt;= $q->{-max_pct}%]" : '(newer)';
+                       $pd = defined($max) ? "[&gt;= $max%]" : '(newer)';
                }
        } else { # o < 0, sort ascending
                my $n = $o - $l;
 
                if (-$n < $total) {
                        $next = $q->qs_html(o => $n, l => $l);
-                       $nd = $q->{r} ? "[&lt;= $q->{-min_pct}%]" : '(newer)';
+                       $nd = defined($min) ? "[&lt;= $min%]" : '(newer)';
                }
                if ($o < -1) {
                        $join = -$n < $total ? ' | ' : "\t";
                        my $p = $o + $l;
                        $prev = $q->qs_html(o => ($p < 0 ? $p : 0));
-                       $pd = $q->{r} ? "[&gt;= $q->{-max_pct}%]" : '(older)';
+                       $pd = defined($max) ? "[&gt;= $max%]" : '(older)';
                }
        }