Commit 26b157b7 authored by stevenjb@google.com's avatar stevenjb@google.com

Protect against NULL PasswordStore

BUG=chromium-os:13799
TEST=See issue

Review URL: http://codereview.chromium.org/7031038

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86459 0039d316-1c4b-4281-b951-d872f2087c98
parent 95cfdc80
......@@ -3609,6 +3609,11 @@ void TestingAutomationProvider::RemoveSavedPassword(
PasswordStore* password_store =
browser->profile()->GetPasswordStore(Profile::EXPLICIT_ACCESS);
if (password_store == NULL) {
reply.SendError("Unable to get password store.");
return;
}
password_store->RemoveLogin(to_remove);
reply.SendSuccess(NULL);
}
......@@ -3624,6 +3629,12 @@ void TestingAutomationProvider::GetSavedPasswords(
// incognito mode.
PasswordStore* password_store =
browser->profile()->GetPasswordStore(Profile::EXPLICIT_ACCESS);
if (password_store == NULL) {
AutomationJSONReply reply(this, reply_message);
reply.SendError("Unable to get password store.");
return;
}
password_store->GetAutofillableLogins(
new AutomationProviderGetPasswordsObserver(this, reply_message));
// Observer deletes itself after sending the result.
......
......@@ -297,6 +297,8 @@ class Profile {
virtual WebDataService* GetWebDataServiceWithoutCreating() = 0;
// Returns the PasswordStore for this profile. This is owned by the Profile.
// This may return NULL if the implementation is unable to create a
// password store (e.g. a corrupt database).
virtual PasswordStore* GetPasswordStore(ServiceAccessType access) = 0;
// Retrieves a pointer to the PrefService that manages the preferences
......
......@@ -27,7 +27,9 @@ PasswordManagerHandler::PasswordManagerHandler()
}
PasswordManagerHandler::~PasswordManagerHandler() {
GetPasswordStore()->RemoveObserver(this);
PasswordStore* store = GetPasswordStore();
if (store)
store->RemoveObserver(this);
}
void PasswordManagerHandler::GetLocalizedValues(
......@@ -76,7 +78,9 @@ void PasswordManagerHandler::Initialize() {
show_passwords_.Init(prefs::kPasswordManagerAllowShowPasswords,
web_ui_->GetProfile()->GetPrefs(), this);
// We should not cache web_ui_->GetProfile(). See crosbug.com/6304.
GetPasswordStore()->AddObserver(this);
PasswordStore* store = GetPasswordStore();
if (store)
store->AddObserver(this);
}
void PasswordManagerHandler::RegisterMessages() {
......@@ -127,19 +131,25 @@ void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) {
}
void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) {
PasswordStore* store = GetPasswordStore();
if (!store)
return;
std::string string_value = UTF16ToUTF8(ExtractStringValue(args));
int index;
base::StringToInt(string_value, &index);
GetPasswordStore()->RemoveLogin(*password_list_[index]);
store->RemoveLogin(*password_list_[index]);
}
void PasswordManagerHandler::RemovePasswordException(
const ListValue* args) {
PasswordStore* store = GetPasswordStore();
if (!store)
return;
std::string string_value = UTF16ToUTF8(ExtractStringValue(args));
int index;
base::StringToInt(string_value, &index);
GetPasswordStore()->RemoveLogin(*password_exception_list_[index]);
store->RemoveLogin(*password_exception_list_[index]);
}
void PasswordManagerHandler::RemoveAllSavedPasswords(
......@@ -147,6 +157,8 @@ void PasswordManagerHandler::RemoveAllSavedPasswords(
// TODO(jhawkins): This will cause a list refresh for every password in the
// list. Add PasswordStore::RemoveAllLogins().
PasswordStore* store = GetPasswordStore();
if (!store)
return;
for (size_t i = 0; i < password_list_.size(); ++i)
store->RemoveLogin(*password_list_[i]);
}
......@@ -154,6 +166,8 @@ void PasswordManagerHandler::RemoveAllSavedPasswords(
void PasswordManagerHandler::RemoveAllPasswordExceptions(
const ListValue* args) {
PasswordStore* store = GetPasswordStore();
if (!store)
return;
for (size_t i = 0; i < password_exception_list_.size(); ++i)
store->RemoveLogin(*password_exception_list_[i]);
}
......
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