From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] imap: quiet Parse::RecDescent errors on bad search queries
Date: Mon, 13 Feb 2023 07:55:33 +0000 [thread overview]
Message-ID: <20230213075533.45233-1-e@80x24.org> (raw)
Parse::RecDescent emits giant errors to STDERR by default
(bypassing $SIG{__WARN__}, even). Shut it up since there's
no good way to pass those back to a client, and we don't want
clients flooding logs with bogus requests.
---
lib/PublicInbox/IMAPsearchqp.pm | 4 +++-
t/imap_searchqp.t | 6 +++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/PublicInbox/IMAPsearchqp.pm b/lib/PublicInbox/IMAPsearchqp.pm
index 9f0c1205..0c37220c 100644
--- a/lib/PublicInbox/IMAPsearchqp.pm
+++ b/lib/PublicInbox/IMAPsearchqp.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# IMAP search query parser. cf RFC 3501
@@ -279,6 +279,8 @@ sub parse {
my $sql = '';
%$q = (sql => \$sql, imap => $imap); # imap = PublicInbox::IMAP obj
# $::RD_TRACE = 1;
+ local $::RD_ERRORS = undef;
+ local $::RD_WARN = undef;
my $res = eval { $prd->search_key(uc($query)) };
return $@ if $@ && $@ =~ /\A(?:BAD|NO) /;
return 'BAD unexpected result' if !$res || $res != $q;
diff --git a/t/imap_searchqp.t b/t/imap_searchqp.t
index e2f49e5a..968d4329 100644
--- a/t/imap_searchqp.t
+++ b/t/imap_searchqp.t
@@ -1,5 +1,5 @@
#!perl -w
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use v5.10.1;
@@ -29,10 +29,10 @@ is($q->{xap}, 'f:"b"', 'charset handled');
$q = $parse->(qq{CHARSET WTF-8 From b});
like($q, qr/\ANO \[/, 'bad charset rejected');
{
- # TODO: squelch errors by default? clients could flood logs
- open my $fh, '>:scalar', \(my $buf) or die;
+ open my $fh, '>:scalar', \(my $buf = '') or die;
local *STDERR = $fh;
$q = $parse->(qq{CHARSET});
+ is($buf, '', 'nothing spewed to STDERR on bad query');
}
like($q, qr/\ABAD /, 'bad charset rejected');
reply other threads:[~2023-02-13 7:55 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=20230213075533.45233-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.
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).