Bug 1544170 Part 4 - Don't infinitely recurse in newChannelForURL on failure, r=loganfsmyth.
authorBrian Hackett <bhackett1024@gmail.com>
Fri, 12 Apr 2019 16:37:00 -1000
changeset 470290 13cfdfc790a066c147ca19da4eb355d774834db7
parent 470289 5e19fc2158c1875050dd8b79062ade3d2476110d
child 470291 3425e11a7a2d6c603912c7d747850e827edda748
push id35892
push userrgurzau@mozilla.com
push dateSat, 20 Apr 2019 09:55:32 +0000
treeherdermozilla-central@a092972b53f0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersloganfsmyth
bugs1544170
milestone68.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 1544170 Part 4 - Don't infinitely recurse in newChannelForURL on failure, r=loganfsmyth. Differential Revision: https://phabricator.services.mozilla.com/D27411
devtools/shared/DevToolsUtils.js
--- a/devtools/shared/DevToolsUtils.js
+++ b/devtools/shared/DevToolsUtils.js
@@ -637,17 +637,17 @@ function mainThreadFetch(urlIn, aOptions
 
 /**
  * Opens a channel for given URL. Tries a bit harder than NetUtil.newChannel.
  *
  * @param {String} url - The URL to open a channel for.
  * @param {Object} options - The options object passed to @method fetch.
  * @return {nsIChannel} - The newly created channel. Throws on failure.
  */
-function newChannelForURL(url, { policy, window, principal }) {
+function newChannelForURL(url, { policy, window, principal }, recursing = false) {
   const securityFlags = Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL;
 
   let uri;
   try {
     uri = Services.io.newURI(url);
   } catch (e) {
     // In the xpcshell tests, the script url is the absolute path of the test
     // file, which will make a malformed URI error be thrown. Add the file
@@ -684,21 +684,27 @@ function newChannelForURL(url, { policy,
     }
 
     channelOptions.loadingPrincipal = prin;
   }
 
   try {
     return NetUtil.newChannel(channelOptions);
   } catch (e) {
+    // Don't infinitely recurse if newChannel keeps throwing.
+    if (recursing) {
+      throw e;
+    }
+
     // In xpcshell tests on Windows, nsExternalProtocolHandler::NewChannel()
     // can throw NS_ERROR_UNKNOWN_PROTOCOL if the external protocol isn't
     // supported by Windows, so we also need to handle the exception here if
     // parsing the URL above doesn't throw.
-    return newChannelForURL("file://" + url, { policy, window, principal });
+    return newChannelForURL("file://" + url, { policy, window, principal },
+                            /* recursing */ true);
   }
 }
 
 // Fetch is defined differently depending on whether we are on the main thread
 // or a worker thread.
 if (this.isWorker) {
   // Services is not available in worker threads, nor is there any other way
   // to fetch a URL. We need to enlist the help from the main thread here, by