[gnome-software: 1/2] appstream: Fix critical warning when appstream contains invalid bundle




commit 3a12c91a09a421ce5f981e039d3b8f684d9fc39a
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Oct 6 15:43:14 2020 +0100

    appstream: Fix critical warning when appstream contains invalid bundle
    
    When some appstream data contains a `<bundle/>` element with no content,
    the following critical warnings are printed:
    ```
    gs_app_add_source: assertion 'source != NULL' failed
    g_strsplit: assertion 'string != NULL' failed
    g_strv_length: assertion 'str_array != NULL' failed
    not handling error not-supported for action search: invalid ID (null) for a flatpak ref
    ```
    
    That’s not very pretty, so avoid the warnings by not trying to add the
    source if the bundle is malformed.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 plugins/core/gs-appstream.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index d514cbf0..2b517c66 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -900,18 +900,23 @@ gs_appstream_refine_app (GsPlugin *plugin,
                for (guint i = 0; i < bundles->len; i++) {
                        XbNode *bundle = g_ptr_array_index (bundles, i);
                        const gchar *kind = xb_node_get_attr (bundle, "type");
-                       gs_app_add_source (app, xb_node_get_text (bundle));
+                       const gchar *bundle_id = xb_node_get_text (bundle);
+
+                       if (bundle_id == NULL || kind == NULL)
+                               continue;
+
+                       gs_app_add_source (app, bundle_id);
                        gs_app_set_bundle_kind (app, as_bundle_kind_from_string (kind));
 
                        /* get the type/name/arch/branch */
                        if (gs_app_get_bundle_kind (app) == AS_BUNDLE_KIND_FLATPAK) {
-                               g_auto(GStrv) split = g_strsplit (xb_node_get_text (bundle), "/", -1);
+                               g_auto(GStrv) split = g_strsplit (bundle_id, "/", -1);
                                if (g_strv_length (split) != 4) {
                                        g_set_error (error,
                                                     GS_PLUGIN_ERROR,
                                                     GS_PLUGIN_ERROR_NOT_SUPPORTED,
                                                     "invalid ID %s for a flatpak ref",
-                                                    xb_node_get_text (bundle));
+                                                    bundle_id);
                                        return FALSE;
                                }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]