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,AWL,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 48DA41FC01 for ; Wed, 10 Jun 2020 07:07:32 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 69/82] imap: support 8000 octet lines Date: Wed, 10 Jun 2020 07:05:06 +0000 Message-Id: <20200610070519.18252-70-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: RFC 2683 section 3.2.1.5 recommends it: > For its part, a server should allow for a command line of at least > 8000 octets. This provides plenty of leeway for accepting reasonable > length commands from clients. The server should send a BAD response > to a command that does not end within the server's maximum accepted > command length. To conserve memory, we won't bother reading the entire line before sending the BAD response and disconnecting them. --- Documentation/standards.perl | 1 + lib/PublicInbox/IMAP.pm | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/standards.perl b/Documentation/standards.perl index 8fc852c722b..b4bda8a9c06 100755 --- a/Documentation/standards.perl +++ b/Documentation/standards.perl @@ -44,6 +44,7 @@ my $rfcs = [ 5322 => 'Internet message format (2008)', 3501 => 'IMAP4rev1', 2177 => 'IMAP IDLE', + 2683 => 'IMAP4 Implementation Recommendations', # 5032 = 'WITHIN search extension for IMAP', 4978 => 'IMAP COMPRESS Extension', # 5182 = 'IMAP Extension for Referencing the Last SEARCH Result', diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index b3c449b0712..2e50415de57 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -36,7 +36,7 @@ for my $mod (qw(Email::Address::XS Mail::Address)) { } die "neither Email::Address::XS nor Mail::Address loaded: $@" if !$Address; -sub LINE_MAX () { 512 } # does RFC 3501 have a limit like RFC 977? +sub LINE_MAX () { 8000 } # RFC 2683 3.2.1.5 # changing this will cause grief for clients which cache sub UID_BLOCK () { 50_000 } @@ -1170,7 +1170,10 @@ sub event_step { my $rbuf = $self->{rbuf} // \(my $x = ''); my $line = index($$rbuf, "\n"); while ($line < 0) { - return $self->close if length($$rbuf) >= LINE_MAX; + if (length($$rbuf) >= LINE_MAX) { + $self->write(\"\* BAD request too long\r\n"); + return $self->close; + } $self->do_read($rbuf, LINE_MAX, length($$rbuf)) or return; $line = index($$rbuf, "\n"); }