Bug 1344498 - Use fallible string.StripWhitespace to avoid OOM r=mcmanus a=gchang
authorValentin Gosu <valentin.gosu@gmail.com>
Thu, 23 Mar 2017 12:54:38 +0100
changeset 377018 bc6deb6af4973ac08028c141cf5b067be604edc6
parent 377017 9bf5caa4b5b58e99bd51a0aa5ae8ac17c8ca2755
child 377019 873e6160117862799207256fffb11d95d702b260
push id7114
push usercbook@mozilla.com
push dateTue, 28 Mar 2017 13:36:07 +0000
treeherdermozilla-beta@f758f44a68de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus, gchang
bugs1344498
milestone53.0
Bug 1344498 - Use fallible string.StripWhitespace to avoid OOM r=mcmanus a=gchang MozReview-Commit-ID: 9wosC46DNcX
netwerk/protocol/data/nsDataHandler.cpp
--- a/netwerk/protocol/data/nsDataHandler.cpp
+++ b/netwerk/protocol/data/nsDataHandler.cpp
@@ -84,17 +84,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);
     }
 
@@ -210,24 +212,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)