Clear the in-memory firmware store only after parsing a valid XML file

If we send junk to UpdateMetadata() the deamon did something like this:

* Clear existing entries from memory
* Try to load junk file into memory -> error

This left us with no entries in the in-memory store, which required the user to
either keep retrying the 'fwupdmgr update' until it worked or just forced them
to restart fwupd so it loaded the old valid store from the cache file.

Now, only clear the in-memory store and add the new firmware entries when
we know the file has been parsed correctly.

Fixes: https://github.com/hughsie/fwupd/issues/35
This commit is contained in:
Richard Hughes 2015-10-27 09:56:04 +00:00
parent d9fa06b8c9
commit 727664fa20

View File

@ -698,6 +698,9 @@ static gboolean
fu_main_daemon_update_metadata (FuMainPrivate *priv, gint fd, gint fd_sig, GError **error)
{
guint8 magic[2];
guint i;
GPtrArray *apps;
g_autoptr(AsStore) store = NULL;
g_autoptr(GBytes) bytes = NULL;
g_autoptr(GBytes) bytes_raw = NULL;
g_autoptr(GBytes) bytes_sig = NULL;
@ -754,13 +757,21 @@ fu_main_daemon_update_metadata (FuMainPrivate *priv, gint fd, gint fd_sig, GErro
if (!fu_keyring_verify_data (kr, bytes_raw, bytes_sig, error))
return FALSE;
/* merge in the new contents */
as_store_remove_all (priv->store);
if (!as_store_from_xml (priv->store,
/* load the store locally until we know it is valid */
store = as_store_new ();
if (!as_store_from_xml (store,
g_bytes_get_data (bytes, NULL),
NULL, error))
return FALSE;
/* add the new application from the store */
as_store_remove_all (priv->store);
apps = as_store_get_apps (store);
for (i = 0; i < apps->len; i++) {
AsApp *app = g_ptr_array_index (apps, i);
as_store_add_app (priv->store, app);
}
/* save the new file */
as_store_set_api_version (priv->store, 0.9);
file = g_file_new_for_path ("/var/cache/app-info/xmls/fwupd.xml");