From 1b9b10d9c6e0d6f93a62a43f720a47f84b5eaec3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 30 Oct 2025 04:26:58 +0000 Subject: [PATCH] searchview: fix uninitialized var on bogus `o=' 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 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 90a319ced..cc263e2b9 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -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} ? "[<= $q->{-min_pct}%]" : '(older)'; + $nd = defined($min) ? "[<= $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} ? "[>= $q->{-max_pct}%]" : '(newer)'; + $pd = defined($max) ? "[>= $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} ? "[<= $q->{-min_pct}%]" : '(newer)'; + $nd = defined($min) ? "[<= $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} ? "[>= $q->{-max_pct}%]" : '(older)'; + $pd = defined($max) ? "[>= $max%]" : '(older)'; } } -- 2.47.3