]> Sergey Matveev's repositories - public-inbox.git/commitdiff
imap: quiet Parse::RecDescent errors on bad search queries
authorEric Wong <e@80x24.org>
Mon, 13 Feb 2023 01:02:12 +0000 (01:02 +0000)
committerEric Wong <e@80x24.org>
Mon, 13 Feb 2023 07:55:17 +0000 (07:55 +0000)
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
t/imap_searchqp.t

index 9f0c1205492dfb23cb67dbd58cebbc58497b5cac..0c37220c9dcf3884d1ddd2b096cb03e1b784fc3e 100644 (file)
@@ -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;
index e2f49e5aa27496290a7e4e4e3f8aa9dfd4c1f78d..968d43297fcd0ee4f51c0b1a80bebbe7ca8d7167 100644 (file)
@@ -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');