[gnome-software] flatpak: Don't add NULL origin apps to cache



commit 85ad4edba40cddcf3c9f263dd2150bdf34b3cdc1
Author: Matthew Leeds <matthew leeds endlessm com>
Date:   Mon Jan 27 13:06:32 2020 -0800

    flatpak: Don't add NULL origin apps to cache
    
    Currently we add all apps created by gs_flatpak_create_app() to the
    cache (which is just a hash table). However if the origin is not set on
    the app at the time we add it to the cache, its hash table key will have
    a "*" for the origin, like
    "user/flatpak/*/desktop/org.test.Chiron/master". Then if the origin is
    later set to something, say "x", the app will still be returned from the
    cache for a gs_plugin_cache_lookup() call with an ID specifying a
    different origin, say "y". This can cause problems; we should be able to
    assume that using the cache doesn't change the origin being used.

 plugins/flatpak/gs-flatpak.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 384676d0..31253af5 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -267,8 +267,15 @@ gs_flatpak_create_app (GsFlatpak *self, const gchar *origin, FlatpakRef *xref)
                gs_app_add_icon (app, icon);
        }
 
+       /* Don't add NULL origin apps to the cache. If the app is later set to
+        * origin x the cache may return it as a match for origin y since the cache
+        * hash table uses as_utils_unique_id_equal() as the equal func and a NULL
+        * origin becomes a "*" in as_utils_unique_id_build().
+        */
+       if (origin != NULL)
+               gs_plugin_cache_add (self->plugin, NULL, app);
+
        /* no existing match, just steal the temp object */
-       gs_plugin_cache_add (self->plugin, NULL, app);
        return g_steal_pointer (&app);
 }
 


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