]> Sergey Matveev's repositories - public-inbox.git/commitdiff
http: fix modification of read-only value
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Tue, 27 Mar 2018 20:09:06 +0000 (20:09 +0000)
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Tue, 27 Mar 2018 20:12:46 +0000 (20:12 +0000)
This fails in the rare case we get a partial send() on "\r\n"
when writing chunked HTTP responses out.

lib/PublicInbox/HTTP.pm

index 3dd49be30ca7dc1330491b5b875e37384fdf7181..bc10814e12634c6b21ab693ed14ba0cf8437f1ec 100644 (file)
@@ -316,9 +316,12 @@ sub more ($$) {
        if (MSG_MORE && !$self->{write_buf_size}) {
                my $n = send($self->{sock}, $_[1], MSG_MORE);
                if (defined $n) {
-                       my $dlen = length($_[1]);
-                       return 1 if $n == $dlen; # all done!
-                       $_[1] = substr($_[1], $n, $dlen - $n);
+                       my $nlen = length($_[1]) - $n;
+                       return 1 if $nlen == 0; # all done!
+                       eval { $_[1] = substr($_[1], $n, $nlen) };
+                       if ($@) { # modification of read-only value:
+                               return $self->write(substr($_[1], $n, $nlen));
+                       }
                        # fall through to normal write:
                }
        }