From 18578fbd0293a9b5561fa38c98f1c52c556c45e1 Mon Sep 17 00:00:00 2001 From: Brian Hackett Date: Fri, 12 Apr 2019 16:37:00 -1000 Subject: [PATCH] Bug 1544170 Part 4 - Don't infinitely recurse in newChannelForURL on failure, r=loganfsmyth. Differential Revision: https://phabricator.services.mozilla.com/D27411 --HG-- extra : rebase_source : 658df8227afa78826ef32b63f87e7c0f9554bda2 --- devtools/shared/DevToolsUtils.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/devtools/shared/DevToolsUtils.js b/devtools/shared/DevToolsUtils.js index d385504e4ab7..e39dbd8c2abc 100644 --- a/devtools/shared/DevToolsUtils.js +++ b/devtools/shared/DevToolsUtils.js @@ -642,7 +642,7 @@ function mainThreadFetch(urlIn, aOptions = { loadFromCache: true, * @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; @@ -689,11 +689,17 @@ function newChannelForURL(url, { policy, window, principal }) { 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); } }