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; ...@@ -19,6 +19,10 @@ using autofill::PasswordForm;
using base::UTF8ToUTF16; using base::UTF8ToUTF16;
using base::UTF16ToUTF8; using base::UTF16ToUTF8;
namespace {
const char kEmptyString[] = "";
}
typeof(&::secret_password_store_sync) typeof(&::secret_password_store_sync)
LibsecretLoader::secret_password_store_sync; LibsecretLoader::secret_password_store_sync;
typeof(&::secret_service_search_sync) typeof(&::secret_service_search_sync)
...@@ -119,14 +123,17 @@ const SecretSchema kLibsecretSchema = { ...@@ -119,14 +123,17 @@ const SecretSchema kLibsecretSchema = {
{"application", SECRET_SCHEMA_ATTRIBUTE_STRING}, {"application", SECRET_SCHEMA_ATTRIBUTE_STRING},
{nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}}; {nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}};
char* GetStringFromAttributes(GHashTable* attrs, const char* keyname) { const char* GetStringFromAttributes(GHashTable* attrs, const char* keyname) {
return static_cast<char*>(g_hash_table_lookup(attrs, keyname)); gpointer value = g_hash_table_lookup(attrs, keyname);
return value ? static_cast<char*>(value) : kEmptyString;
} }
uint32_t GetUintFromAttributes(GHashTable* attrs, const char* keyname) { 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; uint32_t result;
bool value_ok = base::StringToUint(value, &result); bool value_ok = base::StringToUint(static_cast<char*>(value), &result);
DCHECK(value_ok); DCHECK(value_ok);
return result; return result;
} }
......
...@@ -48,6 +48,10 @@ struct MockSecretItem { ...@@ -48,6 +48,10 @@ struct MockSecretItem {
delete value; delete value;
g_hash_table_destroy(attributes); g_hash_table_destroy(attributes);
} }
void RemoveAttribute(const char* keyname) {
g_hash_table_remove(attributes, keyname);
}
}; };
bool Matches(MockSecretItem* item, GHashTable* query) { bool Matches(MockSecretItem* item, GHashTable* query) {
...@@ -818,4 +822,24 @@ TEST_F(NativeBackendLibsecretTest, RemoveLoginsSyncedBetween) { ...@@ -818,4 +822,24 @@ TEST_F(NativeBackendLibsecretTest, RemoveLoginsSyncedBetween) {
CheckRemoveLoginsBetween(SYNCED); 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. // 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