From 15db260efaa0dee19af8bdd979f21df5b7726a2d Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Tue, 3 Dec 2019 06:20:11 +0000 Subject: [PATCH] Bug 1598516 - Don't crash if NS_NewChannelInternal fails. r=mayhemer Looks like this can sometimes fail with moz-extension URIs, so we shouldn't crash Differential Revision: https://phabricator.services.mozilla.com/D54249 --HG-- extra : moz-landing-system : lando --- dom/ipc/ContentChild.cpp | 26 ++++++++++++++++---------- netwerk/ipc/DocumentChannelChild.cpp | 13 ++++++------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 73647b5354be..178b2895d364 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -3680,12 +3680,6 @@ mozilla::ipc::IPCResult ContentChild::RecvCrossProcessRedirect( nullptr, // aCallbacks aArgs.newLoadFlags()); - RefPtr childChannel = do_QueryObject(newChannel); - if (NS_FAILED(rv) || !childChannel) { - MOZ_DIAGNOSTIC_ASSERT(false, "NS_NewChannelInternal failed"); - return IPC_OK(); - } - // This is used to report any errors back to the parent by calling // CrossProcessRedirectFinished. RefPtr httpChild = do_QueryObject(newChannel); @@ -3693,15 +3687,27 @@ mozilla::ipc::IPCResult ContentChild::RecvCrossProcessRedirect( if (httpChild) { rv = httpChild->CrossProcessRedirectFinished(rv); } - nsCOMPtr loadInfo; - MOZ_ALWAYS_SUCCEEDS(newChannel->GetLoadInfo(getter_AddRefs(loadInfo))); Maybe loadInfoArgs; - MOZ_ALWAYS_SUCCEEDS( - mozilla::ipc::LoadInfoToLoadInfoArgs(loadInfo, &loadInfoArgs)); + if (newChannel && NS_SUCCEEDED(rv)) { + nsCOMPtr loadInfo; + MOZ_ALWAYS_SUCCEEDS(newChannel->GetLoadInfo(getter_AddRefs(loadInfo))); + MOZ_ALWAYS_SUCCEEDS( + mozilla::ipc::LoadInfoToLoadInfoArgs(loadInfo, &loadInfoArgs)); + } aResolve( Tuple&>(rv, loadInfoArgs)); }); + if (NS_FAILED(rv)) { + return IPC_OK(); + } + + RefPtr childChannel = do_QueryObject(newChannel); + if (!childChannel) { + rv = NS_ERROR_UNEXPECTED; + return IPC_OK(); + } + if (httpChild) { rv = httpChild->SetChannelId(aArgs.channelId()); if (NS_FAILED(rv)) { diff --git a/netwerk/ipc/DocumentChannelChild.cpp b/netwerk/ipc/DocumentChannelChild.cpp index 5111b21d9077..d61f653d3d18 100644 --- a/netwerk/ipc/DocumentChannelChild.cpp +++ b/netwerk/ipc/DocumentChannelChild.cpp @@ -310,13 +310,6 @@ IPCResult DocumentChannelChild::RecvRedirectToRealChannel( nullptr, // aCallbacks aArgs.newLoadFlags()); - RefPtr httpChild = do_QueryObject(newChannel); - RefPtr childChannel = do_QueryObject(newChannel); - if (NS_FAILED(rv)) { - MOZ_DIAGNOSTIC_ASSERT(false, "NS_NewChannelInternal failed"); - return IPC_OK(); - } - // This is used to report any errors back to the parent by calling // CrossProcessRedirectFinished. auto scopeExit = MakeScopeExit([&]() { @@ -326,6 +319,11 @@ IPCResult DocumentChannelChild::RecvRedirectToRealChannel( mRedirectResolver = nullptr; }); + if (NS_FAILED(rv)) { + return IPC_OK(); + } + + RefPtr httpChild = do_QueryObject(newChannel); if (httpChild) { rv = httpChild->SetChannelId(aArgs.channelId()); } @@ -376,6 +374,7 @@ IPCResult DocumentChannelChild::RecvRedirectToRealChannel( } // connect parent. + nsCOMPtr childChannel = do_QueryInterface(newChannel); if (childChannel) { rv = childChannel->ConnectParent( aArgs.registrarId()); // creates parent channel