Commit 9d66b1db authored by Fergus Dall's avatar Fergus Dall Committed by Commit Bot

Check if GuestOsRegistryService exists before use

guest_os::GetHandler can be called on incognito and guest profiles
which do not have a GuestOsRegistryService. This causes a null pointer
deref crash. Fix this by returning base::nullopt in this case.

Ran new unit test without change to verify the crash, and again with
the rest of the change to verify the fix.

Bug: 1139821
Change-Id: I943d2d7c06b2f897607784a046978a981ed2613e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485414
Commit-Queue: Fergus Dall <sidereal@google.com>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Auto-Submit: Fergus Dall <sidereal@google.com>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818757}
parent 09ee60c6
...@@ -29,6 +29,11 @@ base::Optional<GuestOsRegistryService::Registration> GetHandler( ...@@ -29,6 +29,11 @@ base::Optional<GuestOsRegistryService::Registration> GetHandler(
const GURL& url) { const GURL& url) {
auto* registry_service = auto* registry_service =
guest_os::GuestOsRegistryServiceFactory::GetForProfile(profile); guest_os::GuestOsRegistryServiceFactory::GetForProfile(profile);
if (!registry_service) {
// GuestOsRegistryService does not exist for incognito or guest profiles, so
// don't try and use it.
return base::nullopt;
}
base::Optional<GuestOsRegistryService::Registration> result; base::Optional<GuestOsRegistryService::Registration> result;
for (auto& pair : registry_service->GetEnabledApps()) { for (auto& pair : registry_service->GetEnabledApps()) {
......
...@@ -71,4 +71,13 @@ TEST_F(GuestOsExternalProtocolHandlerTest, MostRecent) { ...@@ -71,4 +71,13 @@ TEST_F(GuestOsExternalProtocolHandlerTest, MostRecent) {
EXPECT_EQ("id2", registration->DesktopFileId()); EXPECT_EQ("id2", registration->DesktopFileId());
} }
TEST_F(GuestOsExternalProtocolHandlerTest, OffTheRecordProfile) {
auto* otr_profile =
profile()->GetOffTheRecordProfile(Profile::OTRProfileID("otr-id"));
EXPECT_FALSE(guest_os::GetHandler(otr_profile, GURL("testscheme:12341234")));
profile()->DestroyOffTheRecordProfile(otr_profile);
}
} // namespace guest_os } // namespace guest_os
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