Commit 8d1453fd authored by Riku Palomäki's avatar Riku Palomäki Committed by Marshall Greenblatt
Browse files

Fix crash if CefAuthCallback outlives the matching URLRequest (issue #2612)

parent 3cf50ed9
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
namespace { namespace {
const void* kAuthCallbackHolderUserDataKey =
static_cast<const void*>(&kAuthCallbackHolderUserDataKey);
class CefBeforeResourceLoadCallbackImpl : public CefRequestCallback { class CefBeforeResourceLoadCallbackImpl : public CefRequestCallback {
public: public:
typedef net::CompletionOnceCallback CallbackType; typedef net::CompletionOnceCallback CallbackType;
...@@ -223,6 +226,19 @@ class CefAuthCallbackImpl : public CefAuthCallback { ...@@ -223,6 +226,19 @@ class CefAuthCallbackImpl : public CefAuthCallback {
IMPLEMENT_REFCOUNTING(CefAuthCallbackImpl); IMPLEMENT_REFCOUNTING(CefAuthCallbackImpl);
}; };
// Invalidates CefAuthCallbackImpl::callback_ if the URLRequest is deleted
// before the callback.
class AuthCallbackHolder : public base::SupportsUserData::Data {
public:
explicit AuthCallbackHolder(CefRefPtr<CefAuthCallbackImpl> callback)
: callback_(callback) {}
~AuthCallbackHolder() override { callback_->Disconnect().Reset(); }
private:
CefRefPtr<CefAuthCallbackImpl> callback_;
};
} // namespace } // namespace
CefNetworkDelegate::CefNetworkDelegate() : force_google_safesearch_(nullptr) {} CefNetworkDelegate::CefNetworkDelegate() : force_google_safesearch_(nullptr) {}
...@@ -401,6 +417,9 @@ net::NetworkDelegate::AuthRequiredResponse CefNetworkDelegate::OnAuthRequired( ...@@ -401,6 +417,9 @@ net::NetworkDelegate::AuthRequiredResponse CefNetworkDelegate::OnAuthRequired(
browser.get(), frame, auth_info.is_proxy, browser.get(), frame, auth_info.is_proxy,
auth_info.challenger.host(), auth_info.challenger.port(), auth_info.challenger.host(), auth_info.challenger.port(),
auth_info.realm, auth_info.scheme, callbackPtr.get())) { auth_info.realm, auth_info.scheme, callbackPtr.get())) {
request->SetUserData(
kAuthCallbackHolderUserDataKey,
std::make_unique<AuthCallbackHolder>(callbackPtr));
return AUTH_REQUIRED_RESPONSE_IO_PENDING; return AUTH_REQUIRED_RESPONSE_IO_PENDING;
} else { } else {
callback = callbackPtr->Disconnect(); callback = callbackPtr->Disconnect();
...@@ -421,6 +440,8 @@ net::NetworkDelegate::AuthRequiredResponse CefNetworkDelegate::OnAuthRequired( ...@@ -421,6 +440,8 @@ net::NetworkDelegate::AuthRequiredResponse CefNetworkDelegate::OnAuthRequired(
auth_info.is_proxy, auth_info.challenger.host(), auth_info.is_proxy, auth_info.challenger.host(),
auth_info.challenger.port(), auth_info.realm, auth_info.scheme, auth_info.challenger.port(), auth_info.realm, auth_info.scheme,
callbackPtr.get())) { callbackPtr.get())) {
request->SetUserData(kAuthCallbackHolderUserDataKey,
std::make_unique<AuthCallbackHolder>(callbackPtr));
return AUTH_REQUIRED_RESPONSE_IO_PENDING; return AUTH_REQUIRED_RESPONSE_IO_PENDING;
} else { } else {
callback = callbackPtr->Disconnect(); callback = callbackPtr->Disconnect();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment