Bug 1312548 - When changing buffer, get the new buffer size too. r=dd
authorDaniel Stenberg <daniel@haxx.se>
Wed, 23 Nov 2016 18:14:07 -0500
changeset 324143 54f07489d3c0b282d407ad437b72d030df981fa6
parent 324142 9b19e41bbd08aea30a201c68e412e734b232d4f7
child 324144 c752386b66319ff71423cd75110a27db13e38aab
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersdd
bugs1312548
milestone53.0a1
Bug 1312548 - When changing buffer, get the new buffer size too. r=dd
netwerk/protocol/http/nsHttpChunkedDecoder.cpp
--- a/netwerk/protocol/http/nsHttpChunkedDecoder.cpp
+++ b/netwerk/protocol/http/nsHttpChunkedDecoder.cpp
@@ -91,24 +91,28 @@ nsHttpChunkedDecoder::ParseChunkRemainin
     NS_PRECONDITION(mChunkRemaining == 0, "chunk remaining should be zero");
     NS_PRECONDITION(count, "unexpected");
 
     *bytesConsumed = 0;
 
     char *p = static_cast<char *>(memchr(buf, '\n', count));
     if (p) {
         *p = 0;
-        if ((p > buf) && (*(p-1) == '\r')) // eliminate a preceding CR
+        count = p - buf; // new length
+        *bytesConsumed = count + 1; // length + newline
+        if ((p > buf) && (*(p-1) == '\r')) { // eliminate a preceding CR
             *(p-1) = 0;
-        *bytesConsumed = p - buf + 1;
+            count--;
+        }
 
         // make buf point to the full line buffer to parse
         if (!mLineBuf.IsEmpty()) {
-            mLineBuf.Append(buf);
+            mLineBuf.Append(buf, count);
             buf = (char *) mLineBuf.get();
+            count = mLineBuf.Length();
         }
 
         if (mWaitEOF) {
             if (*buf) {
                 LOG(("got trailer: %s\n", buf));
                 // allocate a header array for the trailers on demand
                 if (!mTrailers) {
                     mTrailers = new nsHttpHeaderArray();