Bug 1344498 - Use fallible string.StripWhitespace to avoid OOM r=mcmanus a=gchang
MozReview-Commit-ID: 9wosC46DNcX
--- 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)