Bug 1437661 - Use fallible AppendUTF16toUTF8 to avoid OOM crash r=JuniorHsu
authorValentin Gosu <valentin.gosu@gmail.com>
Thu, 07 Mar 2019 17:23:35 +0000
changeset 520930 a451c5f914c4c1fa9e20baaa569a3c54fe04d7b5
parent 520929 bf9beb4c67a568d885b828037bcc704ecdb89fe1
child 520931 be438ca69c7e957273a358cf2891207eaf2f2d53
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJuniorHsu
bugs1437661
milestone67.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 1437661 - Use fallible AppendUTF16toUTF8 to avoid OOM crash r=JuniorHsu Differential Revision: https://phabricator.services.mozilla.com/D22412
netwerk/base/nsNetUtil.cpp
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -1619,33 +1619,39 @@ nsresult NS_NewURI(
         *ioService /* = nullptr */)  // pass in nsIIOService to optimize callers
 {
   nsAutoCString charset;
   encoding->Name(charset);
   return NS_NewURI(result, spec, charset.get(), baseURI, ioService);
 }
 
 nsresult NS_NewURI(
-    nsIURI **result, const nsAString &spec, const char *charset /* = nullptr */,
+    nsIURI **result, const nsAString &aSpec,
+    const char *charset /* = nullptr */, nsIURI *baseURI /* = nullptr */,
+    nsIIOService
+        *ioService /* = nullptr */)  // pass in nsIIOService to optimize callers
+{
+  nsAutoCString spec;
+  if (!AppendUTF16toUTF8(aSpec, spec, mozilla::fallible)) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
+  return NS_NewURI(result, spec, charset, baseURI, ioService);
+}
+
+nsresult NS_NewURI(
+    nsIURI **result, const nsAString &aSpec, NotNull<const Encoding *> encoding,
     nsIURI *baseURI /* = nullptr */,
     nsIIOService
         *ioService /* = nullptr */)  // pass in nsIIOService to optimize callers
 {
-  return NS_NewURI(result, NS_ConvertUTF16toUTF8(spec), charset, baseURI,
-                   ioService);
-}
-
-nsresult NS_NewURI(
-    nsIURI **result, const nsAString &spec, NotNull<const Encoding *> encoding,
-    nsIURI *baseURI /* = nullptr */,
-    nsIIOService
-        *ioService /* = nullptr */)  // pass in nsIIOService to optimize callers
-{
-  return NS_NewURI(result, NS_ConvertUTF16toUTF8(spec), encoding, baseURI,
-                   ioService);
+  nsAutoCString spec;
+  if (!AppendUTF16toUTF8(aSpec, spec, mozilla::fallible)) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
+  return NS_NewURI(result, spec, encoding, baseURI, ioService);
 }
 
 nsresult NS_NewURI(
     nsIURI **result, const char *spec, nsIURI *baseURI /* = nullptr */,
     nsIIOService
         *ioService /* = nullptr */)  // pass in nsIIOService to optimize callers
 {
   return NS_NewURI(result, nsDependentCString(spec), nullptr, baseURI,