From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 8E6821FA0C for ; Wed, 10 Jun 2020 07:07:28 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 50/82] imap: avoid uninitialized warnings on incomplete commands Date: Wed, 10 Jun 2020 07:04:47 +0000 Message-Id: <20200610070519.18252-51-e@yhbt.net> In-Reply-To: <20200610070519.18252-1-e@yhbt.net> References: <20200610070519.18252-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: No point in spewing "uninitialized" warnings into logs when the cat jumps on the Enter key. --- lib/PublicInbox/IMAP.pm | 7 +++++-- t/imapd.t | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index e726307a678..0452d6df937 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -862,14 +862,17 @@ sub process_line ($$) { cmd_done($self, $tag); } else { # this is weird auth_challenge_ok($self) // - "$tag BAD Error in IMAP command $req: ". - "Unknown command\r\n"; + ($tag // '*') . + ' BAD Error in IMAP command '. + ($req // '(???)'). + ": Unknown command\r\n"; } }; my $err = $@; if ($err && $self->{sock}) { $l =~ s/\r?\n//s; err($self, 'error from: %s (%s)', $l, $err); + $tag //= '*'; $res = "$tag BAD program fault - command not performed\r\n"; } return 0 unless defined $res; diff --git a/t/imapd.t b/t/imapd.t index 45ee401a1e0..11b56b09dbe 100644 --- a/t/imapd.t +++ b/t/imapd.t @@ -367,11 +367,22 @@ ok($mic->close, 'CLOSE works'); ok(!$mic->close, 'CLOSE not idempotent'); ok($mic->logout, 'logged out'); +{ + my $c = tcp_connect($sock); + $c->autoflush(1); + like(<$c>, qr/\* OK/, 'got a greeting'); + print $c "\r\n"; + like(<$c>, qr/\A\* BAD Error in IMAP command/, 'empty line'); + print $c "tagonly\r\n"; + like(<$c>, qr/\Atagonly BAD Error in IMAP command/, 'tag-only line'); +} + $td->kill; $td->join; is($?, 0, 'no error in exited process'); open my $fh, '<', $err or BAIL_OUT("open $err failed: $!"); my $eout = do { local $/; <$fh> }; unlike($eout, qr/wide/i, 'no Wide character warnings'); +unlike($eout, qr/uninitialized/i, 'no uninitialized warnings'); done_testing;