Commit 810e42d6 authored by Regan Hsu's avatar Regan Hsu Committed by Commit Bot

[CrOS PhoneHub] Do not access SerializedNavigationEntry vector if empty.

Accessing an empty sessions::SessionTab's |navigations| vector is
resulting in an out of bounds access, causing
BrowserTabsMetadataFetcherImpl to crash.

Fixed: 1142562
Bug: 1106937
Change-Id: I0ec890135f6acafd61a39a7d06b52ef1956bed96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2522497
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824826}
parent 6aff9986
......@@ -24,6 +24,12 @@ GetSortedMetadataWithoutFavicons(const sync_sessions::SyncedSession* session) {
const sessions::SessionWindow& window = window_pair.second->wrapped_window;
for (const std::unique_ptr<sessions::SessionTab>& tab : window.tabs) {
int selected_index = tab->normalized_navigation_index();
if (selected_index + 1 > tab->navigations.size() ||
tab->navigations.empty()) {
continue;
}
const sessions::SerializedNavigationEntry& current_navigation =
tab->navigations.at(selected_index);
......
......@@ -227,6 +227,17 @@ TEST_F(BrowserTabsMetadataFetcherImplTest, NoTabsOpen) {
AttemptFetch();
CheckIsExpectedMetadata({});
auto synced_session_window_two =
std::make_unique<sync_sessions::SyncedSessionWindow>();
// Add a tab without navigation(s), i.e no available metadata.
auto tab = std::make_unique<sessions::SessionTab>();
synced_session_window_two->wrapped_window.tabs.push_back(std::move(tab));
AddWindow(std::move(synced_session_window_two));
AttemptFetch();
CheckIsExpectedMetadata({});
}
TEST_F(BrowserTabsMetadataFetcherImplTest, BelowMaximumNumberOfTabs) {
......
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