Commit 23d0d92f authored by Christos Froussios's avatar Christos Froussios Committed by Commit Bot

[Password Manager] Update old key elements only when best match exists

When we update parts of the key of existing credentials, we need the
pre-update data. We take this data from the password store, as found in
|best_matches|. Sometimes, the updated credential is not in the matches.
This CL fixes a crash from
https://chromium-review.googlesource.com/c/chromium/src/+/941522 where
we presumed that the credentials are always in the matches.

Bug: 833171, 817750
Change-Id: Id2aae19b307d65c3527cdf9a6c80703dc6bfeb34
Reviewed-on: https://chromium-review.googlesource.com/1012848
Commit-Queue: Christos Froussios <cfroussios@chromium.org>
Reviewed-by: default avatarMaxim Kolosovskiy <kolos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551303}
parent b926fe9e
......@@ -1577,14 +1577,13 @@ base::Optional<PasswordForm> PasswordFormManager::UpdatePendingAndGetOldKey(
// PasswordStore primary key, the old primary key must be used in order to
// match and update the existing entry.
old_primary_key = pending_credentials_;
old_primary_key->username_element =
best_matches()
.at(pending_credentials_.username_value)
->username_element;
old_primary_key->password_element =
best_matches()
.at(pending_credentials_.username_value)
->password_element;
// TODO(crbug.com/833171) It is possible for best_matches to not contain the
// username being updated. Add comments and a test, when we realise why.
auto best_match = best_matches().find(pending_credentials_.username_value);
if (best_match != best_matches().end()) {
old_primary_key->username_element = best_match->second->username_element;
old_primary_key->password_element = best_match->second->password_element;
}
pending_credentials_.password_element = observed_form_.password_element;
pending_credentials_.username_element = observed_form_.username_element;
pending_credentials_.submit_element = observed_form_.submit_element;
......
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