[gnome-software/wip/kalev/gnome-3-22: 64/96] trivial: Do not crash when loading an invalid runtime



commit 9c028a8c1118fcc8bf311a1e3dd8de1eb7a3b26b
Author: Richard Hughes <richard hughsie com>
Date:   Wed Feb 22 12:47:45 2017 +0000

    trivial: Do not crash when loading an invalid runtime
    
    Including 'runtime=foo' in the metadata file for a *runtime* makes gnome-software explode.

 data/tests/flatpak/org.test.Runtime/metadata |    1 -
 src/gs-app.c                                 |    4 ++++
 src/plugins/gs-appstream.c                   |    5 +++++
 3 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/data/tests/flatpak/org.test.Runtime/metadata b/data/tests/flatpak/org.test.Runtime/metadata
index cf5655d..16f0fa1 100644
--- a/data/tests/flatpak/org.test.Runtime/metadata
+++ b/data/tests/flatpak/org.test.Runtime/metadata
@@ -1,4 +1,3 @@
 [Runtime]
 name=org.test.Runtime
-runtime=org.test.Runtime/x86_64/master
 sdk=org.test.Runtime/x86_64/master
diff --git a/src/gs-app.c b/src/gs-app.c
index d4a1027..956b083 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -1502,6 +1502,8 @@ gs_app_set_runtime (GsApp *app, GsApp *runtime)
 {
        g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&app->mutex);
        g_return_if_fail (GS_IS_APP (app));
+       g_return_if_fail (app != runtime);
+       g_return_if_fail (runtime->kind == AS_APP_KIND_RUNTIME);
        g_set_object (&app->runtime, runtime);
 }
 
@@ -1536,6 +1538,8 @@ gs_app_set_update_runtime (GsApp *app, GsApp *runtime)
 {
        g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&app->mutex);
        g_return_if_fail (GS_IS_APP (app));
+       g_return_if_fail (app != runtime);
+       g_return_if_fail (runtime->kind == AS_APP_KIND_RUNTIME);
        g_set_object (&app->update_runtime, runtime);
 }
 
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index 73c2db7..082e714 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -371,6 +371,11 @@ gs_refine_item_management_plugin (GsPlugin *plugin, GsApp *app, AsApp *item)
                                g_autoptr(GsApp) app2 = NULL;
                                app2 = gs_appstream_create_runtime (plugin, app, runtime);
                                if (app2 != NULL) {
+                                       if (app == app2) {
+                                               g_warning ("%s runtime cannot have runtime!",
+                                                          gs_app_get_unique_id (app));
+                                               break;
+                                       }
                                        g_debug ("runtime for %s is %s",
                                                 gs_app_get_unique_id (app),
                                                 runtime);


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