user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] www: avoid warnings on bad offsets for Xapian
Date: Sun, 22 May 2016 20:54:44 +0000	[thread overview]
Message-ID: <20160522205444.11617-1-e@80x24.org> (raw)

The offset argument must be an integer for Xapian,
however users (or bots) type the darndest things.

AFAIK this has no security implications besides triggering
a warning (which could lead to out-of-space-errors)
---
 lib/PublicInbox/SearchView.pm | 3 ++-
 lib/PublicInbox/View.pm       | 5 ++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index c0cd1ff..e3dc22f 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -263,10 +263,11 @@ use PublicInbox::Hval;
 sub new {
 	my ($class, $cgi) = @_;
 	my $r = $cgi->param('r');
+	my ($off) = (($cgi->param('o') || '0') =~ /(\d+)/);
 	bless {
 		q => $cgi->param('q'),
 		x => $cgi->param('x') || '',
-		o => int($cgi->param('o') || 0) || 0,
+		o => $off,
 		r => (defined $r && $r ne '0'),
 	}, $class;
 }
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 2194981..4360991 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -840,13 +840,12 @@ sub emit_topics {
 
 sub emit_index_topics {
 	my ($state) = @_;
-	my $off = $state->{ctx}->{cgi}->param('o');
-	$off = 0 unless defined $off;
+	my ($off) = (($state->{ctx}->{cgi}->param('o') || '0') =~ /(\d+)/);
 	$state->{order} = [];
 	$state->{subjs} = {};
 	$state->{latest} = {};
 	my $max = 25;
-	my %opts = ( offset => int $off, limit => $max * 4 );
+	my %opts = ( offset => $off, limit => $max * 4 );
 	while (scalar @{$state->{order}} < $max) {
 		my $sres = $state->{srch}->query('', \%opts);
 		my $nr = scalar @{$sres->{msgs}} or last;

                 reply	other threads:[~2016-05-22 20:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160522205444.11617-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).