Bug 1344498 - Use fallible string.StripWhitespace to avoid OOM r=mcmanus
authorValentin Gosu <valentin.gosu@gmail.com>
Thu, 23 Mar 2017 12:54:38 +0100
changeset 349369 47fbdd127336308711e081faa3a88446f94872ae
parent 349368 533f7d421ef64569130ddbaf69425b702a837d69
child 349370 59f60e7f92ca592d02704ddce5ab4257836f290c
push id31550
push usercbook@mozilla.com
push dateFri, 24 Mar 2017 13:22:27 +0000
treeherdermozilla-central@473e0b201761 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1344498
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1344498 - Use fallible string.StripWhitespace to avoid OOM r=mcmanus MozReview-Commit-ID: 9wosC46DNcX
netwerk/protocol/data/nsDataHandler.cpp
--- a/netwerk/protocol/data/nsDataHandler.cpp
+++ b/netwerk/protocol/data/nsDataHandler.cpp
@@ -90,17 +90,19 @@ nsDataHandler::NewURI(const nsACString &
         if (NS_FAILED(rv))
             return rv;
 
         // Strip whitespace unless this is text, where whitespace is important
         // Don't strip escaped whitespace though (bug 391951)
         if (base64 || (strncmp(contentType.get(),"text/",5) != 0 &&
                        contentType.Find("xml") == kNotFound)) {
             // it's ascii encoded binary, don't let any spaces in
-            spec.StripWhitespace();
+            if (!spec.StripWhitespace(mozilla::fallible)) {
+                return NS_ERROR_OUT_OF_MEMORY;
+            }
         }
 
         uri = do_CreateInstance(kSimpleURICID, &rv);
         if (NS_FAILED(rv))
             return rv;
         rv = uri->SetSpec(spec);
     }
 
@@ -216,24 +218,28 @@ nsDataHandler::ParseURI(nsCString& spec,
             *semiColon = '\0';
 
         if (semiColon == buffer || base64 == buffer) {
             // there is no content type, but there are other parameters
             contentType.AssignLiteral("text/plain");
         } else {
             contentType.Assign(buffer);
             ToLowerCase(contentType);
-            contentType.StripWhitespace();
+            if (!contentType.StripWhitespace(mozilla::fallible)) {
+                return NS_ERROR_OUT_OF_MEMORY;
+            }
         }
 
         if (semiColon && contentCharset) {
             char *charset = PL_strcasestr(semiColon + 1, "charset=");
             if (charset) {
                 contentCharset->Assign(charset + sizeof("charset=") - 1);
-                contentCharset->StripWhitespace();
+                if (!contentCharset->StripWhitespace(mozilla::fallible)) {
+                    return NS_ERROR_OUT_OF_MEMORY;
+                }
             }
         }
 
         free(buffer);
     }
 
     if (dataBuffer) {
         // Split encoded data from terminal "#ref" (if present)