[gnome-software] trivial: Do not allow access to the GModule from the plugin API



commit 6fbe55833b6e6d1e98bd5302a513335b314a70d1
Author: Richard Hughes <richard hughsie com>
Date:   Fri Nov 25 10:11:46 2016 +0000

    trivial: Do not allow access to the GModule from the plugin API
    
    Just provide a method to return the symbol pointer itself.

 src/gs-plugin-loader.c  |   30 +++++-------------------------
 src/gs-plugin-private.h |    3 ++-
 src/gs-plugin.c         |   21 +++++++++++++++------
 3 files changed, 22 insertions(+), 32 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index ef0a800..0732903 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -408,11 +408,7 @@ gs_plugin_loader_run_adopt (GsPluginLoader *plugin_loader, GsAppList *list)
        for (i = 0; i < priv->plugins->len; i++) {
                GsPluginAdoptAppFunc adopt_app_func = NULL;
                GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
-               if (!gs_plugin_get_enabled (plugin))
-                       continue;
-               g_module_symbol (gs_plugin_get_module (plugin),
-                                "gs_plugin_adopt_app",
-                                (gpointer *) &adopt_app_func);
+               adopt_app_func = gs_plugin_get_symbol (plugin, "gs_plugin_adopt_app");
                if (adopt_app_func == NULL)
                        continue;
                for (j = 0; j < gs_app_list_length (list); j++) {
@@ -467,12 +463,8 @@ gs_plugin_loader_call_vfunc (GsPluginLoaderJob *job,
        g_autoptr(GError) error_local = NULL;
        g_autoptr(AsProfileTask) ptask = NULL;
 
-       /* no point */
-       if (!gs_plugin_get_enabled (plugin))
-               return TRUE;
-
        /* load the possible symbol */
-       g_module_symbol (gs_plugin_get_module (plugin), job->function_name, &func);
+       func = gs_plugin_get_symbol (plugin, job->function_name);
        if (func == NULL)
                return TRUE;
 
@@ -4344,13 +4336,9 @@ gs_plugin_loader_update_thread_cb (GTask *task,
                guint j;
 
                GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
-               if (!gs_plugin_get_enabled (plugin))
-                       continue;
                if (g_task_return_error_if_cancelled (task))
                        return;
-               g_module_symbol (gs_plugin_get_module (plugin),
-                                job->function_name,
-                                (gpointer *) &plugin_app_func);
+               plugin_app_func = gs_plugin_get_symbol (plugin, job->function_name);
                if (plugin_app_func == NULL)
                        continue;
 
@@ -4443,17 +4431,9 @@ gs_plugin_loader_get_plugin_supported (GsPluginLoader *plugin_loader,
                                       const gchar *function_name)
 {
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
-       guint i;
-
-       for (i = 0; i < priv->plugins->len; i++) {
+       for (guint i = 0; i < priv->plugins->len; i++) {
                GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
-               gpointer dummy = NULL;
-               if (!gs_plugin_get_enabled (plugin))
-                       continue;
-               g_module_symbol (gs_plugin_get_module (plugin),
-                                function_name,
-                                (gpointer *) &dummy);
-               if (dummy != NULL)
+               if (gs_plugin_get_symbol (plugin, function_name) != NULL)
                        return TRUE;
        }
        return FALSE;
diff --git a/src/gs-plugin-private.h b/src/gs-plugin-private.h
index 36d7647..eda4b8d 100644
--- a/src/gs-plugin-private.h
+++ b/src/gs-plugin-private.h
@@ -64,7 +64,8 @@ void           gs_plugin_set_running_other            (GsPlugin       *plugin,
                                                         gboolean        running_other);
 GPtrArray      *gs_plugin_get_rules                    (GsPlugin       *plugin,
                                                         GsPluginRule    rule);
-GModule                *gs_plugin_get_module                   (GsPlugin       *plugin);
+gpointer        gs_plugin_get_symbol                   (GsPlugin       *plugin,
+                                                        const gchar    *function_name);
 
 G_END_DECLS
 
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 8cab6d7..4b11826 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -325,20 +325,29 @@ gs_plugin_action_stop (GsPlugin *plugin)
 }
 
 /**
- * gs_plugin_get_module:
+ * gs_plugin_get_symbol (skip):
  * @plugin: a #GsPlugin
  *
- * Gets the external module that backs the plugin.
+ * Gets the symbol from the module that backs the plugin. If the plugin is not
+ * enabled then no symbol is returned.
  *
- * Returns: the #GModule, or %NULL
+ * Returns: the pointer to the symbol, or %NULL
  *
  * Since: 3.22
  **/
-GModule *
-gs_plugin_get_module (GsPlugin *plugin)
+gpointer
+gs_plugin_get_symbol (GsPlugin *plugin, const gchar *function_name)
 {
        GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
-       return priv->module;
+       gpointer func = NULL;
+
+       /* disabled plugins shouldn't be checked */
+       if (!priv->enabled)
+               return NULL;
+
+       /* look up the symbol */
+       g_module_symbol (priv->module, function_name, &func);
+       return func;
 }
 
 /**


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