Bug 790617 - Part 2 - don't use atoi to parse header. r=cbiesinger
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Wed, 19 Sep 2012 17:44:54 +0900
changeset 107574 2d6537a4762764eef1fdcff8b0c31c4a5795b7fb
parent 107573 df2fbeb72ca1c8a1d523f17604d11d6fbe9d61a0
child 107575 ca4f5cf1fbed6097f7007d06c66638ed115b68f8
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewerscbiesinger
bugs790617
milestone18.0a1
Bug 790617 - Part 2 - don't use atoi to parse header. r=cbiesinger
netwerk/protocol/http/HttpBaseChannel.cpp
netwerk/streamconv/converters/nsMultiMixedConv.cpp
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -1575,17 +1575,17 @@ HttpBaseChannel::SetupReplacementChannel
           const char *clen =
             mRequestHead.PeekHeader(nsHttp::Content_Length);
           if (!ctype) {
             ctype = "application/octet-stream";
           }
           if (clen) {
             uploadChannel->SetUploadStream(mUploadStream,
                                            nsDependentCString(ctype),
-                                           atoi(clen));
+                                           nsCRT::atoll(clen));
           }
         }
       }
     }
     // since preserveMethod is true, we need to ensure that the appropriate 
     // request method gets set on the channel, regardless of whether or not 
     // we set the upload stream above. This means SetRequestMethod() will
     // be called twice if ExplicitSetUploadStream() gets called above.
--- a/netwerk/streamconv/converters/nsMultiMixedConv.cpp
+++ b/netwerk/streamconv/converters/nsMultiMixedConv.cpp
@@ -949,17 +949,17 @@ nsMultiMixedConv::ParseHeaders(nsIChanne
 
             nsAutoCString headerVal(colon + 1);
             headerVal.CompressWhitespace();
 
             // examine header
             if (headerStr.LowerCaseEqualsLiteral("content-type")) {
                 mContentType = headerVal;
             } else if (headerStr.LowerCaseEqualsLiteral("content-length")) {
-                mContentLength = atoi(headerVal.get()); // XXX 64-bit math?
+                mContentLength = nsCRT::atoll(headerVal.get());
             } else if (headerStr.LowerCaseEqualsLiteral("content-disposition")) {
                 mContentDisposition = headerVal;
             } else if (headerStr.LowerCaseEqualsLiteral("set-cookie")) {
                 nsCOMPtr<nsIHttpChannelInternal> httpInternal =
                     do_QueryInterface(aChannel);
                 if (httpInternal) {
                     httpInternal->SetCookie(headerVal.get());
                 }
@@ -983,24 +983,24 @@ nsMultiMixedConv::ParseHeaders(nsIChanne
                 }
                 else {
                     tmpPtr = (char *) strchr(range, '-');
                     if (!tmpPtr)
                         return NS_ERROR_FAILURE;
                     
                     tmpPtr[0] = '\0';
                     
-                    mByteRangeStart = atoi(range); // XXX want 64-bit conv
+                    mByteRangeStart = nsCRT::atoll(range);
                     tmpPtr++;
-                    mByteRangeEnd = atoi(tmpPtr);
+                    mByteRangeEnd = nsCRT::atoll(tmpPtr);
                 }
 
                 mIsByteRangeRequest = true;
                 if (mContentLength == LL_MAXUINT)
-                    mContentLength = uint64_t(int64_t(mByteRangeEnd - mByteRangeStart + int64_t(1)));
+                    mContentLength = uint64_t(mByteRangeEnd - mByteRangeStart + 1);
             }
         }
         *newLine = tmpChar;
         newLine += lineFeedIncrement;
         cursorLen -= (newLine - cursor);
         cursor = newLine;
     }