Merge pull request #10676 from qazbnm456/fix-unhandle-null-pointer

Add a null-pointer check before processing base::SupportsUserData::GetUserData
This commit is contained in:
Cheng Zhao 2017-10-03 20:18:51 +09:00 committed by GitHub
commit 150a4797a4
2 changed files with 17 additions and 9 deletions

View file

@ -6,6 +6,7 @@
#include "atom/browser/atom_browser_main_parts.h" #include "atom/browser/atom_browser_main_parts.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/supports_user_data.h" #include "base/supports_user_data.h"
namespace mate { namespace mate {
@ -46,16 +47,19 @@ void TrackableObjectBase::Destroy() {
} }
void TrackableObjectBase::AttachAsUserData(base::SupportsUserData* wrapped) { void TrackableObjectBase::AttachAsUserData(base::SupportsUserData* wrapped) {
wrapped->SetUserData(kTrackedObjectKey, new IDUserData(weak_map_id_)); wrapped->SetUserData(kTrackedObjectKey,
base::MakeUnique<IDUserData>(weak_map_id_));
} }
// static // static
int32_t TrackableObjectBase::GetIDFromWrappedClass(base::SupportsUserData* w) { int32_t TrackableObjectBase::GetIDFromWrappedClass(
auto id = static_cast<IDUserData*>(w->GetUserData(kTrackedObjectKey)); base::SupportsUserData* wrapped) {
if (id) if (wrapped) {
return *id; auto id = static_cast<IDUserData*>(wrapped->GetUserData(kTrackedObjectKey));
else if (id)
return 0; return *id;
}
return 0;
} }
// static // static

View file

@ -82,8 +82,12 @@ void ToDictionary(base::DictionaryValue* details, net::URLRequest* request) {
int frame_id = info->GetRenderFrameID(); int frame_id = info->GetRenderFrameID();
auto* webContents = content::WebContents::FromRenderFrameHost( auto* webContents = content::WebContents::FromRenderFrameHost(
content::RenderFrameHost::FromID(process_id, frame_id)); content::RenderFrameHost::FromID(process_id, frame_id));
details->SetInteger("webContentsId", int webContentsId = atom::api::WebContents::GetIDFromWrappedClass(
atom::api::WebContents::GetIDFromWrappedClass(webContents)); webContents);
// webContentsId must be greater than zero
if (webContentsId)
details->SetInteger("webContentsId", webContentsId);
details->SetString("resourceType", details->SetString("resourceType",
ResourceTypeToString(info->GetResourceType())); ResourceTypeToString(info->GetResourceType()));
} else { } else {