gnome-software/0003-crash-under-gs-flatpak-refine-app-unlocked.patch

387 lines
14 KiB
Diff

diff -up gnome-software-42.2/lib/gs-appstream.c.3 gnome-software-42.2/lib/gs-appstream.c
--- gnome-software-42.2/lib/gs-appstream.c.3 2022-06-13 14:34:05.477145977 +0200
+++ gnome-software-42.2/lib/gs-appstream.c 2022-06-13 14:36:26.640218337 +0200
@@ -20,7 +20,13 @@ GsApp *
gs_appstream_create_app (GsPlugin *plugin, XbSilo *silo, XbNode *component, GError **error)
{
GsApp *app;
- g_autoptr(GsApp) app_new = gs_app_new (NULL);
+ g_autoptr(GsApp) app_new = NULL;
+
+ g_return_val_if_fail (GS_IS_PLUGIN (plugin), NULL);
+ g_return_val_if_fail (XB_IS_SILO (silo), NULL);
+ g_return_val_if_fail (XB_IS_NODE (component), NULL);
+
+ app_new = gs_app_new (NULL);
/* refine enough to get the unique ID */
if (!gs_appstream_refine_app (plugin, app_new, silo, component,
@@ -967,6 +973,11 @@ gs_appstream_refine_app (GsPlugin *plugi
g_autoptr(GPtrArray) launchables = NULL;
g_autoptr(XbNode) req = NULL;
+ g_return_val_if_fail (GS_IS_PLUGIN (plugin), FALSE);
+ g_return_val_if_fail (GS_IS_APP (app), FALSE);
+ g_return_val_if_fail (XB_IS_SILO (silo), FALSE);
+ g_return_val_if_fail (XB_IS_NODE (component), FALSE);
+
/* is compatible */
req = xb_node_query_first (component,
"requires/id[@type='id']"
@@ -1411,6 +1422,11 @@ gs_appstream_search (GsPlugin *plugin,
{ AS_SEARCH_TOKEN_MATCH_NONE, NULL }
};
+ g_return_val_if_fail (GS_IS_PLUGIN (plugin), FALSE);
+ g_return_val_if_fail (XB_IS_SILO (silo), FALSE);
+ g_return_val_if_fail (values != NULL, FALSE);
+ g_return_val_if_fail (GS_IS_APP_LIST (list), FALSE);
+
/* add some weighted queries */
for (guint i = 0; queries[i].xpath != NULL; i++) {
g_autoptr(GError) error_query = NULL;
@@ -1487,6 +1503,11 @@ gs_appstream_add_category_apps (GsPlugin
{
GPtrArray *desktop_groups;
+ g_return_val_if_fail (GS_IS_PLUGIN (plugin), FALSE);
+ g_return_val_if_fail (XB_IS_SILO (silo), FALSE);
+ g_return_val_if_fail (GS_IS_CATEGORY (category), FALSE);
+ g_return_val_if_fail (GS_IS_APP_LIST (list), FALSE);
+
desktop_groups = gs_category_get_desktop_groups (category);
if (desktop_groups->len == 0) {
g_warning ("no desktop_groups for %s", gs_category_get_id (category));
@@ -1577,6 +1598,9 @@ gs_appstream_add_categories (XbSilo *sil
GCancellable *cancellable,
GError **error)
{
+ g_return_val_if_fail (XB_IS_SILO (silo), FALSE);
+ g_return_val_if_fail (list != NULL, FALSE);
+
for (guint j = 0; j < list->len; j++) {
GsCategory *parent = GS_CATEGORY (g_ptr_array_index (list, j));
GPtrArray *children = gs_category_get_children (parent);
@@ -1611,6 +1635,9 @@ gs_appstream_add_popular (XbSilo *silo,
g_autoptr(GError) error_local = NULL;
g_autoptr(GPtrArray) array = NULL;
+ g_return_val_if_fail (XB_IS_SILO (silo), FALSE);
+ g_return_val_if_fail (GS_IS_APP_LIST (list), FALSE);
+
/* find out how many packages are in each category */
array = xb_silo_query (silo,
"components/component/kudos/"
@@ -1648,6 +1675,10 @@ gs_appstream_add_recent (GsPlugin *plugi
g_autoptr(GError) error_local = NULL;
g_autoptr(GPtrArray) array = NULL;
+ g_return_val_if_fail (GS_IS_PLUGIN (plugin), FALSE);
+ g_return_val_if_fail (XB_IS_SILO (silo), FALSE);
+ g_return_val_if_fail (GS_IS_APP_LIST (list), FALSE);
+
/* use predicate conditions to the max */
xpath = g_strdup_printf ("components/component/releases/"
"release[@timestamp>%" G_GUINT64_FORMAT "]/../..",
@@ -1686,6 +1717,10 @@ gs_appstream_add_alternates (XbSilo *sil
g_autoptr(GPtrArray) ids = NULL;
g_autoptr(GString) xpath = g_string_new (NULL);
+ g_return_val_if_fail (XB_IS_SILO (silo), FALSE);
+ g_return_val_if_fail (GS_IS_APP (app), FALSE);
+ g_return_val_if_fail (GS_IS_APP_LIST (list), FALSE);
+
/* probably a package we know nothing about */
if (gs_app_get_id (app) == NULL)
return TRUE;
@@ -1743,6 +1778,9 @@ gs_appstream_add_featured (XbSilo *silo,
g_autoptr(GError) error_local = NULL;
g_autoptr(GPtrArray) array = NULL;
+ g_return_val_if_fail (XB_IS_SILO (silo), FALSE);
+ g_return_val_if_fail (GS_IS_APP_LIST (list), FALSE);
+
/* find out how many packages are in each category */
array = xb_silo_query (silo,
"components/component/custom/value[@key='GnomeSoftware::FeatureTile']/../..|"
@@ -1782,6 +1820,11 @@ gs_appstream_url_to_app (GsPlugin *plugi
g_autofree gchar *xpath = NULL;
g_autoptr(GPtrArray) components = NULL;
+ g_return_val_if_fail (GS_IS_PLUGIN (plugin), FALSE);
+ g_return_val_if_fail (XB_IS_SILO (silo), FALSE);
+ g_return_val_if_fail (GS_IS_APP_LIST (list), FALSE);
+ g_return_val_if_fail (url != NULL, FALSE);
+
/* not us */
scheme = gs_utils_get_url_scheme (url);
if (g_strcmp0 (scheme, "appstream") != 0)
@@ -1812,6 +1855,9 @@ gs_appstream_component_add_keyword (XbBu
g_autoptr(XbBuilderNode) keyword = NULL;
g_autoptr(XbBuilderNode) keywords = NULL;
+ g_return_if_fail (XB_IS_BUILDER_NODE (component));
+ g_return_if_fail (str != NULL);
+
/* create <keywords> if it does not already exist */
keywords = xb_builder_node_get_child (component, "keywords", NULL);
if (keywords == NULL)
@@ -1831,6 +1877,9 @@ gs_appstream_component_add_provide (XbBu
g_autoptr(XbBuilderNode) provide = NULL;
g_autoptr(XbBuilderNode) provides = NULL;
+ g_return_if_fail (XB_IS_BUILDER_NODE (component));
+ g_return_if_fail (str != NULL);
+
/* create <provides> if it does not already exist */
provides = xb_builder_node_get_child (component, "provides", NULL);
if (provides == NULL)
@@ -1850,6 +1899,9 @@ gs_appstream_component_add_category (XbB
g_autoptr(XbBuilderNode) category = NULL;
g_autoptr(XbBuilderNode) categories = NULL;
+ g_return_if_fail (XB_IS_BUILDER_NODE (component));
+ g_return_if_fail (str != NULL);
+
/* create <categories> if it does not already exist */
categories = xb_builder_node_get_child (component, "categories", NULL);
if (categories == NULL)
@@ -1868,6 +1920,9 @@ gs_appstream_component_add_icon (XbBuild
{
g_autoptr(XbBuilderNode) icon = NULL;
+ g_return_if_fail (XB_IS_BUILDER_NODE (component));
+ g_return_if_fail (str != NULL);
+
/* create <icon>str</icon> if it does not already exist */
icon = xb_builder_node_get_child (component, "icon", NULL);
if (icon == NULL) {
@@ -1881,7 +1936,11 @@ gs_appstream_component_add_icon (XbBuild
void
gs_appstream_component_add_extra_info (XbBuilderNode *component)
{
- const gchar *kind = xb_builder_node_get_attr (component, "type");
+ const gchar *kind;
+
+ g_return_if_fail (XB_IS_BUILDER_NODE (component));
+
+ kind = xb_builder_node_get_attr (component, "type");
/* add the gnome-software-specific 'Addon' group and ensure they
* all have an icon set */
@@ -1927,9 +1986,14 @@ gs_appstream_component_add_extra_info (X
void
gs_appstream_component_fix_url (XbBuilderNode *component, const gchar *baseurl)
{
- const gchar *text = xb_builder_node_get_text (component);
+ const gchar *text;
g_autofree gchar *url = NULL;
+ g_return_if_fail (XB_IS_BUILDER_NODE (component));
+ g_return_if_fail (baseurl != NULL);
+
+ text = xb_builder_node_get_text (component);
+
if (text == NULL)
return;
diff -up gnome-software-42.2/plugins/flatpak/gs-flatpak.c.3 gnome-software-42.2/plugins/flatpak/gs-flatpak.c
--- gnome-software-42.2/plugins/flatpak/gs-flatpak.c.3 2022-05-30 13:43:00.000000000 +0200
+++ gnome-software-42.2/plugins/flatpak/gs-flatpak.c 2022-06-13 14:34:05.480145978 +0200
@@ -467,10 +467,18 @@ gs_flatpak_create_source (GsFlatpak *sel
}
static void
+gs_flatpak_invalidate_silo (GsFlatpak *self)
+{
+ g_rw_lock_writer_lock (&self->silo_lock);
+ if (self->silo != NULL)
+ xb_silo_invalidate (self->silo);
+ g_rw_lock_writer_unlock (&self->silo_lock);
+}
+
+static void
gs_flatpak_internal_data_changed (GsFlatpak *self)
{
g_autoptr(GMutexLocker) locker = NULL;
- g_autoptr(GRWLockWriterLocker) writer_locker = NULL;
/* drop the installed refs cache */
locker = g_mutex_locker_new (&self->installed_refs_mutex);
@@ -487,10 +495,7 @@ gs_flatpak_internal_data_changed (GsFlat
g_hash_table_remove_all (self->broken_remotes);
g_clear_pointer (&locker, g_mutex_locker_free);
- writer_locker = g_rw_lock_writer_locker_new (&self->silo_lock);
- if (self->silo)
- xb_silo_invalidate (self->silo);
- g_clear_pointer (&writer_locker, g_rw_lock_writer_locker_free);
+ gs_flatpak_invalidate_silo (self);
self->requires_full_rescan = TRUE;
}
@@ -2009,10 +2014,7 @@ gs_flatpak_refresh (GsFlatpak *self,
g_mutex_unlock (&self->installed_refs_mutex);
/* manually do this in case we created the first appstream file */
- g_rw_lock_reader_lock (&self->silo_lock);
- if (self->silo != NULL)
- xb_silo_invalidate (self->silo);
- g_rw_lock_reader_unlock (&self->silo_lock);
+ gs_flatpak_invalidate_silo (self);
/* update AppStream metadata */
if (!gs_flatpak_refresh_appstream (self, cache_age_secs, interactive, cancellable, error))
@@ -3197,6 +3199,20 @@ gs_flatpak_refine_app_unlocked (GsFlatpa
locker = g_rw_lock_reader_locker_new (&self->silo_lock);
+ if (self->silo == NULL) {
+ g_clear_pointer (&locker, g_rw_lock_reader_locker_free);
+ if (!gs_flatpak_rescan_appstream_store (self, interactive, cancellable, error))
+ return FALSE;
+
+ locker = g_rw_lock_reader_locker_new (&self->silo_lock);
+ if (self->silo == NULL) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "failed to setup XbSilo for '%s'",
+ gs_flatpak_get_id (self));
+ return FALSE;
+ }
+ }
+
/* always do AppStream properties */
if (!gs_flatpak_refine_appstream (self, app, self->silo, flags, interactive, cancellable, error))
return FALSE;
@@ -3394,6 +3410,13 @@ gs_flatpak_refine_wildcard (GsFlatpak *s
locker = g_rw_lock_reader_locker_new (&self->silo_lock);
+ if (self->silo == NULL) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "failed to setup XbSilo for '%s'",
+ gs_flatpak_get_id (self));
+ return FALSE;
+ }
+
/* find all apps when matching any prefixes */
xpath = g_strdup_printf ("components/component/id[text()='%s']/..", id);
components = xb_silo_query (self->silo, xpath, 0, &error_local);
@@ -3487,10 +3510,7 @@ gs_flatpak_app_remove_source (GsFlatpak
}
/* invalidate cache */
- g_rw_lock_reader_lock (&self->silo_lock);
- if (self->silo != NULL)
- xb_silo_invalidate (self->silo);
- g_rw_lock_reader_unlock (&self->silo_lock);
+ gs_flatpak_invalidate_silo (self);
gs_app_set_state (app, is_remove ? GS_APP_STATE_UNAVAILABLE : GS_APP_STATE_AVAILABLE);
@@ -3953,6 +3973,13 @@ gs_flatpak_search (GsFlatpak *self,
return FALSE;
locker = g_rw_lock_reader_locker_new (&self->silo_lock);
+ if (self->silo == NULL) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "failed to setup XbSilo for '%s'",
+ gs_flatpak_get_id (self));
+ return FALSE;
+ }
+
if (!gs_appstream_search (self->plugin, self->silo, values, list_tmp,
cancellable, error))
return FALSE;
@@ -4022,6 +4049,12 @@ gs_flatpak_add_category_apps (GsFlatpak
return FALSE;
locker = g_rw_lock_reader_locker_new (&self->silo_lock);
+ if (self->silo == NULL) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "failed to setup XbSilo for '%s'",
+ gs_flatpak_get_id (self));
+ return FALSE;
+ }
return gs_appstream_add_category_apps (self->plugin, self->silo,
category, list,
cancellable, error);
@@ -4040,6 +4073,12 @@ gs_flatpak_add_categories (GsFlatpak *se
return FALSE;
locker = g_rw_lock_reader_locker_new (&self->silo_lock);
+ if (self->silo == NULL) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "failed to setup XbSilo for '%s'",
+ gs_flatpak_get_id (self));
+ return FALSE;
+ }
return gs_appstream_add_categories (self->silo,
list, cancellable, error);
}
@@ -4058,6 +4097,12 @@ gs_flatpak_add_popular (GsFlatpak *self,
return FALSE;
locker = g_rw_lock_reader_locker_new (&self->silo_lock);
+ if (self->silo == NULL) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "failed to setup XbSilo for '%s'",
+ gs_flatpak_get_id (self));
+ return FALSE;
+ }
if (!gs_appstream_add_popular (self->silo, list_tmp,
cancellable, error))
return FALSE;
@@ -4081,6 +4126,12 @@ gs_flatpak_add_featured (GsFlatpak *self
return FALSE;
locker = g_rw_lock_reader_locker_new (&self->silo_lock);
+ if (self->silo == NULL) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "failed to setup XbSilo for '%s'",
+ gs_flatpak_get_id (self));
+ return FALSE;
+ }
if (!gs_appstream_add_featured (self->silo, list_tmp,
cancellable, error))
return FALSE;
@@ -4105,6 +4156,12 @@ gs_flatpak_add_alternates (GsFlatpak *se
return FALSE;
locker = g_rw_lock_reader_locker_new (&self->silo_lock);
+ if (self->silo == NULL) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "failed to setup XbSilo for '%s'",
+ gs_flatpak_get_id (self));
+ return FALSE;
+ }
if (!gs_appstream_add_alternates (self->silo, app, list_tmp,
cancellable, error))
return FALSE;
@@ -4129,6 +4186,12 @@ gs_flatpak_add_recent (GsFlatpak *self,
return FALSE;
locker = g_rw_lock_reader_locker_new (&self->silo_lock);
+ if (self->silo == NULL) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "failed to setup XbSilo for '%s'",
+ gs_flatpak_get_id (self));
+ return FALSE;
+ }
if (!gs_appstream_add_recent (self->plugin, self->silo, list_tmp, age,
cancellable, error))
return FALSE;
@@ -4154,6 +4217,12 @@ gs_flatpak_url_to_app (GsFlatpak *self,
return FALSE;
locker = g_rw_lock_reader_locker_new (&self->silo_lock);
+ if (self->silo == NULL) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "failed to setup XbSilo for '%s'",
+ gs_flatpak_get_id (self));
+ return FALSE;
+ }
if (!gs_appstream_url_to_app (self->plugin, self->silo, list_tmp, url, cancellable, error))
return FALSE;