From 154772a71a0fadafc4416356bf8c1391405f4bd2 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 5 Aug 2016 16:19:34 +0100 Subject: trivial: Check if the flatpak ID is valid before using --- libappstream-glib/as-app.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index 3af6046..d1c14d9 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -2963,6 +2963,30 @@ as_app_add_icon (AsApp *app, AsIcon *icon) g_ptr_array_add (priv->icons, g_object_ref (icon)); } +static void +as_app_parse_flatpak_id (AsApp *app, const gchar *bundle_id) +{ + AsAppPrivate *priv = GET_PRIVATE (app); + g_auto(GStrv) split = NULL; + + /* not set */ + if (bundle_id == NULL) + return; + + /* split into type/id/arch/branch */ + split = g_strsplit (bundle_id, "/", -1); + if (g_strv_length (split) != 4) { + g_warning ("invalid flatpak bundle ID: %s", bundle_id); + return; + } + + /* only set if not already set */ + if (priv->architectures->len == 0) + as_app_add_arch (app, split[2]); + if (priv->branch == NULL) + as_app_set_branch (app, split[3]); +} + /** * as_app_add_bundle: * @app: a #AsApp instance. @@ -2989,12 +3013,12 @@ as_app_add_bundle (AsApp *app, AsBundle *bundle) } /* set the architecture and branch */ - if (as_bundle_get_kind (bundle) == AS_BUNDLE_KIND_FLATPAK) { - g_auto(GStrv) split = g_strsplit (as_bundle_get_id (bundle), "/", -1); - if (priv->architectures->len == 0) - as_app_add_arch (app, split[2]); - if (priv->branch == NULL) - as_app_set_branch (app, split[3]); + switch (as_bundle_get_kind (bundle)) { + case AS_BUNDLE_KIND_FLATPAK: + as_app_parse_flatpak_id (app, as_bundle_get_id (bundle)); + break; + default: + break; } g_ptr_array_add (priv->bundles, g_object_ref (bundle)); -- cgit v1.2.1