]> Sergey Matveev's repositories - public-inbox.git/commitdiff
imap: avoid uninitialized warnings on incomplete commands
authorEric Wong <e@yhbt.net>
Wed, 10 Jun 2020 07:04:47 +0000 (07:04 +0000)
committerEric Wong <e@yhbt.net>
Sat, 13 Jun 2020 07:55:45 +0000 (07:55 +0000)
No point in spewing "uninitialized" warnings into logs when
the cat jumps on the Enter key.

lib/PublicInbox/IMAP.pm
t/imapd.t

index e726307a6785ba98794b06aac66302f323ee4bbf..0452d6df9373bafbd749a8757ae4f655363d9193 100644 (file)
@@ -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;
index 45ee401a1e0cfa598d10c07dde11da7a4b50c8f5..11b56b09dbeb0113d335e5e73e72387a5f8f1eb5 100644 (file)
--- 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;