about summary refs log tree commit homepage
path: root/lib/PublicInbox/HTTP.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-27 20:09:06 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-27 20:12:46 +0000
commitcc615e445899ad719b7b84babae0cf7907b2a3e3 (patch)
tree543d2f7bb85b5ee66f367737277c08caf519486a /lib/PublicInbox/HTTP.pm
parent956abe9ad5f13a0d1755262be412d6a54fda72e9 (diff)
downloadpublic-inbox-cc615e445899ad719b7b84babae0cf7907b2a3e3.tar.gz
This fails in the rare case we get a partial send() on "\r\n"
when writing chunked HTTP responses out.
Diffstat (limited to 'lib/PublicInbox/HTTP.pm')
-rw-r--r--lib/PublicInbox/HTTP.pm9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 3dd49be3..bc10814e 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -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:
                 }
         }