diff options
-rw-r--r-- | lib/PublicInbox/HTTP.pm | 6 | ||||
-rw-r--r-- | t/httpd-corner.t | 12 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index 6c4c20d7..8988e7d2 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -70,7 +70,11 @@ sub rbuf_process { # We do not support Trailers in chunked requests, for now # (they are rarely-used and git (as of 2.7.2) does not use them) - return quit($self, 400) if $r == -1 || $env{HTTP_TRAILER}; + if ($r == -1 || $env{HTTP_TRAILER} || + # this length-check is necessary for PURE_PERL=1: + ($r == -2 && length($self->{rbuf}) > 0x4000)) { + return quit($self, 400); + } return $self->watch_read(1) if $r < 0; # incomplete $self->{rbuf} = substr($self->{rbuf}, $r); diff --git a/t/httpd-corner.t b/t/httpd-corner.t index 833eb429..8670846c 100644 --- a/t/httpd-corner.t +++ b/t/httpd-corner.t @@ -84,6 +84,18 @@ my $spawn_httpd = sub { is($body, "hello world\n", 'callback body matches expected'); } +{ + my $conn = conn_for($sock, 'excessive header'); + $SIG{PIPE} = 'IGNORE'; + $conn->write("GET /callback HTTP/1.0\r\n"); + foreach my $i (1..500000) { + last unless $conn->write("X-xxxxxJunk-$i: omg\r\n"); + } + ok(!$conn->write("\r\n"), 'broken request'); + ok($conn->read(my $buf, 8192), 'read response'); + my ($head, $body) = split(/\r\n\r\n/, $buf); + like($head, qr/\b400\b/, 'got 400 response'); +} # Unix domain sockets { |