Commit 480ca0e5 authored by dvadym's avatar dvadym Committed by Commit bot

Fill empty fields from keyring result with default values.

This is fixing of crashes in libsecret when some of fields from keyring result are absent.

BUG=453218

Review URL: https://codereview.chromium.org/891463002

Cr-Commit-Position: refs/heads/master@{#313710}
parent 82e87d58
......@@ -19,6 +19,10 @@ using autofill::PasswordForm;
using base::UTF8ToUTF16;
using base::UTF16ToUTF8;
namespace {
const char kEmptyString[] = "";
}
typeof(&::secret_password_store_sync)
LibsecretLoader::secret_password_store_sync;
typeof(&::secret_service_search_sync)
......@@ -119,14 +123,17 @@ const SecretSchema kLibsecretSchema = {
{"application", SECRET_SCHEMA_ATTRIBUTE_STRING},
{nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}};
char* GetStringFromAttributes(GHashTable* attrs, const char* keyname) {
return static_cast<char*>(g_hash_table_lookup(attrs, keyname));
const char* GetStringFromAttributes(GHashTable* attrs, const char* keyname) {
gpointer value = g_hash_table_lookup(attrs, keyname);
return value ? static_cast<char*>(value) : kEmptyString;
}
uint32_t GetUintFromAttributes(GHashTable* attrs, const char* keyname) {
char* value = static_cast<char*>(g_hash_table_lookup(attrs, keyname));
gpointer value = g_hash_table_lookup(attrs, keyname);
if (!value)
return uint32_t();
uint32_t result;
bool value_ok = base::StringToUint(value, &result);
bool value_ok = base::StringToUint(static_cast<char*>(value), &result);
DCHECK(value_ok);
return result;
}
......
......@@ -48,6 +48,10 @@ struct MockSecretItem {
delete value;
g_hash_table_destroy(attributes);
}
void RemoveAttribute(const char* keyname) {
g_hash_table_remove(attributes, keyname);
}
};
bool Matches(MockSecretItem* item, GHashTable* query) {
......@@ -818,4 +822,24 @@ TEST_F(NativeBackendLibsecretTest, RemoveLoginsSyncedBetween) {
CheckRemoveLoginsBetween(SYNCED);
}
TEST_F(NativeBackendLibsecretTest, SomeKeyringAttributesAreMissing) {
// Absent attributes should be filled with default values.
NativeBackendLibsecret backend(42);
backend.AddLogin(form_google_);
EXPECT_EQ(1u, global_mock_libsecret_items.size());
// Remove a string attribute.
global_mock_libsecret_items[0]->RemoveAttribute("avatar_url");
// Remove an integer attribute.
global_mock_libsecret_items[0]->RemoveAttribute("ssl_valid");
ScopedVector<autofill::PasswordForm> form_list;
backend.GetAutofillableLogins(&form_list);
EXPECT_EQ(1u, form_list.size());
EXPECT_EQ(GURL(""), form_list[0]->avatar_url);
EXPECT_FALSE(form_list[0]->ssl_valid);
}
// TODO(mdm): add more basic tests here at some point.
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