summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-08-05 16:19:34 +0100
committerRichard Hughes <richard@hughsie.com>2016-08-05 16:19:34 +0100
commit154772a71a0fadafc4416356bf8c1391405f4bd2 (patch)
tree0196e4d62938a5b6f69f15cffca9e045ad13d183
parent9d02d627df34b817be68f3dcb09a33623011f670 (diff)
downloadappstream-glib-154772a71a0fadafc4416356bf8c1391405f4bd2.tar.gz
trivial: Check if the flatpak ID is valid before using
-rw-r--r--libappstream-glib/as-app.c36
1 files 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));