From a71755e1b6b6ad5128c9bc1642b460aff3e595c0 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Mon, 8 Oct 2018 15:04:45 -0700 Subject: [PATCH] fix: crash in webRequest due to unsafe static_cast upstream was changed to wrap the network delegate see https://chromium.googlesource.com/chromium/src/+/69.0.3497.106/services/network/network_context.cc#948 --- atom/browser/api/atom_api_web_request.cc | 6 ++---- atom/browser/net/url_request_context_getter.cc | 4 +++- atom/browser/net/url_request_context_getter.h | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_web_request.cc b/atom/browser/api/atom_api_web_request.cc index 2dc48a4c0333..b5cfeb134007 100644 --- a/atom/browser/api/atom_api_web_request.cc +++ b/atom/browser/api/atom_api_web_request.cc @@ -49,11 +49,9 @@ void CallNetworkDelegateMethod( URLPatterns patterns, Listener listener) { // Force creating network delegate. - net::URLRequestContext* context = - url_request_context_getter->GetURLRequestContext(); + url_request_context_getter->GetURLRequestContext(); // Then call the method. - AtomNetworkDelegate* network_delegate = - static_cast(context->network_delegate()); + auto* network_delegate = url_request_context_getter->network_delegate(); (network_delegate->*method)(type, std::move(patterns), std::move(listener)); } diff --git a/atom/browser/net/url_request_context_getter.cc b/atom/browser/net/url_request_context_getter.cc index d4d30e1b8082..be3af544a92d 100644 --- a/atom/browser/net/url_request_context_getter.cc +++ b/atom/browser/net/url_request_context_getter.cc @@ -313,7 +313,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { if (!url_request_context_) { std::unique_ptr builder = std::make_unique(); - builder->set_network_delegate(std::make_unique()); + auto network_delegate = std::make_unique(); + network_delegate_ = network_delegate.get(); + builder->set_network_delegate(std::move(network_delegate)); ct_delegate_.reset(new brightray::RequireCTDelegate); auto cert_verifier = std::make_unique(ct_delegate_.get()); diff --git a/atom/browser/net/url_request_context_getter.h b/atom/browser/net/url_request_context_getter.h index 861f33bc60a3..f35d451943a3 100644 --- a/atom/browser/net/url_request_context_getter.h +++ b/atom/browser/net/url_request_context_getter.h @@ -26,6 +26,7 @@ class RequireCTDelegate; namespace atom { class AtomBrowserContext; +class AtomNetworkDelegate; class AtomURLRequestJobFactory; class ResourceContext; @@ -44,6 +45,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { return top_job_factory_.get(); } + AtomNetworkDelegate* network_delegate() const { return network_delegate_; } + private: friend class AtomBrowserContext; @@ -99,6 +102,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { URLRequestContextGetter::Handle* context_handle_; net::URLRequestContext* url_request_context_; + AtomNetworkDelegate* network_delegate_; content::ProtocolHandlerMap protocol_handlers_; content::URLRequestInterceptorScopedVector protocol_interceptors_; bool context_shutting_down_;