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



commit 30a7f0e739f30eba8a296e97cac41c111653df68
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]