Commit 93a2e830 authored by Arthur Eubanks's avatar Arthur Eubanks Committed by Chromium LUCI CQ

Check returned SafeBrowsingPrivateEventRouter for null

SafeBrowsingPrivateEventRouterFactory::GetForProfile() can return
nullptr, calling methods on nullptr is undefined behavior and causes
some tests in unit_tests to crash under UBSan VPtr.

Fixes
$ ./out/Default/unit_tests --gtest_filter='*ChromeDownloadManagerDelegateTestWithSafeBrowsing*'
under UBSan VPtr

Bug: 1137496
Change-Id: I461f5d1235da4bc98bce22a1d7a4183ed11c4f25
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2568667Reviewed-by: default avatarDominique Fauteux-Chapleau <domfc@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Arthur Eubanks <aeubanks@google.com>
Cr-Commit-Position: refs/heads/master@{#833160}
parent 5c7965c9
......@@ -358,13 +358,16 @@ void MaybeReportDangerousDownloadBlocked(
return;
}
std::string raw_digest_sha256 = download->GetHash();
extensions::SafeBrowsingPrivateEventRouterFactory::GetForProfile(profile)
->OnDangerousDownloadEvent(
download->GetURL(), download_path,
base::HexEncode(raw_digest_sha256.data(), raw_digest_sha256.size()),
danger_type, download->GetMimeType(), download->GetTotalBytes(),
safe_browsing::EventResult::BLOCKED);
auto* router =
extensions::SafeBrowsingPrivateEventRouterFactory::GetForProfile(profile);
if (router) {
std::string raw_digest_sha256 = download->GetHash();
router->OnDangerousDownloadEvent(
download->GetURL(), download_path,
base::HexEncode(raw_digest_sha256.data(), raw_digest_sha256.size()),
danger_type, download->GetMimeType(), download->GetTotalBytes(),
safe_browsing::EventResult::BLOCKED);
}
#endif
}
......
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