From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id E0D2A63384D for ; Thu, 24 Sep 2015 03:37:23 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/7] nntp: avoid infinite loop on partial read Date: Thu, 24 Sep 2015 03:37:19 +0000 Message-Id: <20150924033721.26231-6-e@80x24.org> In-Reply-To: <20150924033721.26231-1-e@80x24.org> References: <20150924033721.26231-1-e@80x24.org> List-Id: Oops :x --- lib/PublicInbox/NNTP.pm | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 52d6a64..6c661a1 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -879,22 +879,18 @@ sub event_write { sub event_read { my ($self) = @_; use constant LINE_MAX => 512; # RFC 977 section 2.3 - my $line; my $r = 1; -again: + + my $buf = $self->read(LINE_MAX) or return $self->close; + $self->{rbuf} .= $$buf; while ($r > 0 && $self->{rbuf} =~ s/\A\s*([^\r\n]+)\r?\n//) { - $line = $1; + my $line = $1; my $t0 = now(); $r = eval { $self->process_line($line) }; my $d = $self->{long_res} ? ' deferred['.fileno($self->{sock}).']' : ''; out($self, "$line - %0.6f$d", now() - $t0); } - unless (defined $line) { - my $buf = $self->read(LINE_MAX) or return $self->close; - $self->{rbuf} .= $$buf; - goto again; - } return $self->close if $r < 0; my $len = length($self->{rbuf}); -- EW