Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a null-pointer check before processing base::SupportsUserData::GetUserData #10676

Merged
merged 1 commit into from Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions atom/browser/api/trackable_object.cc
Expand Up @@ -6,6 +6,7 @@

#include "atom/browser/atom_browser_main_parts.h"
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/supports_user_data.h"

namespace mate {
Expand Down Expand Up @@ -46,16 +47,19 @@ void TrackableObjectBase::Destroy() {
}

void TrackableObjectBase::AttachAsUserData(base::SupportsUserData* wrapped) {
wrapped->SetUserData(kTrackedObjectKey, new IDUserData(weak_map_id_));
wrapped->SetUserData(kTrackedObjectKey,
base::MakeUnique<IDUserData>(weak_map_id_));
}

// static
int32_t TrackableObjectBase::GetIDFromWrappedClass(base::SupportsUserData* w) {
auto id = static_cast<IDUserData*>(w->GetUserData(kTrackedObjectKey));
if (id)
return *id;
else
return 0;
int32_t TrackableObjectBase::GetIDFromWrappedClass(
base::SupportsUserData* wrapped) {
if (wrapped) {
auto id = static_cast<IDUserData*>(wrapped->GetUserData(kTrackedObjectKey));
if (id)
return *id;
}
return 0;
}

// static
Expand Down
8 changes: 6 additions & 2 deletions atom/browser/net/atom_network_delegate.cc
Expand Up @@ -82,8 +82,12 @@ void ToDictionary(base::DictionaryValue* details, net::URLRequest* request) {
int frame_id = info->GetRenderFrameID();
auto* webContents = content::WebContents::FromRenderFrameHost(
content::RenderFrameHost::FromID(process_id, frame_id));
details->SetInteger("webContentsId",
atom::api::WebContents::GetIDFromWrappedClass(webContents));
int webContentsId = atom::api::WebContents::GetIDFromWrappedClass(
webContents);

// webContentsId must be greater than zero
if (webContentsId)
details->SetInteger("webContentsId", webContentsId);
details->SetString("resourceType",
ResourceTypeToString(info->GetResourceType()));
} else {
Expand Down