[gnome-software/wip/kalev/gnome-3-22: 12/96] trivial: Don't crash when a plugin exports a NULL symbol



commit 1626581f871b78ecb5031eed7f2791180e9f0b50
Author: Richard Hughes <richard hughsie com>
Date:   Wed Nov 9 09:38:23 2016 +0000

    trivial: Don't crash when a plugin exports a NULL symbol
    
    Technically Coverity is correct, it is possible to export a NULL symbol from a
    plugin. Check the symbol address is not NULL before attempting to use it,
    rather than checking if the symbol just exists.

 src/gs-plugin-loader.c |  176 ++++++++++++++++++++++--------------------------
 1 files changed, 81 insertions(+), 95 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 1f1d03a..4c3ef1b 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -677,9 +677,7 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
 {
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
        g_autoptr(GsAppList) list = NULL;
-       GsPluginResultsFunc plugin_func = NULL;
        GsPlugin *plugin;
-       gboolean exists;
        gboolean ret = TRUE;
        guint i;
        g_autoptr(AsProfileTask) ptask = NULL;
@@ -696,6 +694,7 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
        /* run each plugin */
        list = gs_app_list_new ();
        for (i = 0; i < priv->plugins->len; i++) {
+               GsPluginResultsFunc plugin_func = NULL;
                g_autoptr(GError) error_local = NULL;
                g_autoptr(AsProfileTask) ptask2 = NULL;
 
@@ -707,10 +706,10 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
                }
 
                /* get symbol */
-               exists = g_module_symbol (gs_plugin_get_module (plugin),
-                                         function_name,
-                                         (gpointer *) &plugin_func);
-               if (!exists)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
 
                /* run function */
@@ -1017,16 +1016,15 @@ gs_plugin_loader_run_action (GsPluginLoader *plugin_loader,
                             GCancellable *cancellable,
                             GError **error)
 {
-       GsPluginActionFunc plugin_func = NULL;
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
        GsPlugin *plugin;
        gboolean anything_ran = FALSE;
-       gboolean exists;
        gboolean ret;
        guint i;
 
        /* run each plugin */
        for (i = 0; i < priv->plugins->len; i++) {
+               GsPluginActionFunc plugin_func = NULL;
                g_autoptr(AsProfileTask) ptask = NULL;
                g_autoptr(GError) error_local = NULL;
 
@@ -1036,10 +1034,10 @@ gs_plugin_loader_run_action (GsPluginLoader *plugin_loader,
                if (g_cancellable_set_error_if_cancelled (cancellable, error)) {
                        return FALSE;
                }
-               exists = g_module_symbol (gs_plugin_get_module (plugin),
-                                         function_name,
-                                         (gpointer *) &plugin_func);
-               if (!exists)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
@@ -1883,7 +1881,6 @@ gs_plugin_loader_search_thread_cb (GTask *task,
        GError *error = NULL;
        GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
        GsPlugin *plugin;
-       GsPluginSearchFunc plugin_func = NULL;
        guint i;
        g_auto(GStrv) values = NULL;
 
@@ -1897,18 +1894,18 @@ gs_plugin_loader_search_thread_cb (GTask *task,
                return;
        }
        for (i = 0; i < priv->plugins->len; i++) {
+               GsPluginSearchFunc plugin_func = NULL;
                g_autoptr(AsProfileTask) ptask = NULL;
                g_autoptr(GError) error_local = NULL;
                plugin = g_ptr_array_index (priv->plugins, i);
                if (!gs_plugin_get_enabled (plugin))
                        continue;
-               ret = g_task_return_error_if_cancelled (task);
-               if (ret)
+               if (g_task_return_error_if_cancelled (task))
                        return;
-               ret = g_module_symbol (gs_plugin_get_module (plugin),
-                                      function_name,
-                                      (gpointer *) &plugin_func);
-               if (!ret)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
@@ -2068,13 +2065,12 @@ gs_plugin_loader_search_files_thread_cb (GTask *task,
                plugin = g_ptr_array_index (priv->plugins, i);
                if (!gs_plugin_get_enabled (plugin))
                        continue;
-               ret = g_task_return_error_if_cancelled (task);
-               if (ret)
+               if (g_task_return_error_if_cancelled (task))
                        return;
-               ret = g_module_symbol (gs_plugin_get_module (plugin),
-                                      function_name,
-                                      (gpointer *) &plugin_func);
-               if (!ret)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
@@ -2235,13 +2231,12 @@ gs_plugin_loader_search_what_provides_thread_cb (GTask *task,
                plugin = g_ptr_array_index (priv->plugins, i);
                if (!gs_plugin_get_enabled (plugin))
                        continue;
-               ret = g_task_return_error_if_cancelled (task);
-               if (ret)
+               if (g_task_return_error_if_cancelled (task))
                        return;
-               ret = g_module_symbol (gs_plugin_get_module (plugin),
-                                      function_name,
-                                      (gpointer *) &plugin_func);
-               if (!ret)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
@@ -2443,13 +2438,12 @@ gs_plugin_loader_get_categories_thread_cb (GTask *task,
                plugin = g_ptr_array_index (priv->plugins, i);
                if (!gs_plugin_get_enabled (plugin))
                        continue;
-               ret = g_task_return_error_if_cancelled (task);
-               if (ret)
+               if (g_task_return_error_if_cancelled (task))
                        return;
-               ret = g_module_symbol (gs_plugin_get_module (plugin),
-                                      function_name,
-                                      (gpointer *) &plugin_func);
-               if (!ret)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
@@ -2577,13 +2571,12 @@ gs_plugin_loader_get_category_apps_thread_cb (GTask *task,
                plugin = g_ptr_array_index (priv->plugins, i);
                if (!gs_plugin_get_enabled (plugin))
                        continue;
-               ret = g_task_return_error_if_cancelled (task);
-               if (ret)
+               if (g_task_return_error_if_cancelled (task))
                        return;
-               ret = g_module_symbol (gs_plugin_get_module (plugin),
-                                      function_name,
-                                      (gpointer *) &plugin_func);
-               if (!ret)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
@@ -2891,14 +2884,13 @@ gs_plugin_loader_review_action_thread_cb (GTask *task,
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
        GsPlugin *plugin;
-       GsPluginReviewFunc plugin_func = NULL;
        gboolean anything_ran = FALSE;
-       gboolean exists;
        gboolean ret;
        guint i;
 
        /* run each plugin */
        for (i = 0; i < priv->plugins->len; i++) {
+               GsPluginReviewFunc plugin_func = NULL;
                g_autoptr(AsProfileTask) ptask = NULL;
                g_autoptr(GError) error_local = NULL;
 
@@ -2909,10 +2901,10 @@ gs_plugin_loader_review_action_thread_cb (GTask *task,
                        g_task_return_error (task, error);
                }
 
-               exists = g_module_symbol (gs_plugin_get_module (plugin),
-                                         state->function_name,
-                                         (gpointer *) &plugin_func);
-               if (!exists)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                state->function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
@@ -3291,13 +3283,12 @@ gs_plugin_loader_auth_action_thread_cb (GTask *task,
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
        GsPlugin *plugin;
-       GsPluginAuthFunc plugin_func = NULL;
-       gboolean exists;
        gboolean ret;
        guint i;
 
        /* run each plugin */
        for (i = 0; i < priv->plugins->len; i++) {
+               GsPluginAuthFunc plugin_func = NULL;
                g_autoptr(AsProfileTask) ptask = NULL;
                g_autoptr(GError) error_local = NULL;
 
@@ -3308,10 +3299,10 @@ gs_plugin_loader_auth_action_thread_cb (GTask *task,
                        g_task_return_error (task, error);
                }
 
-               exists = g_module_symbol (gs_plugin_get_module (plugin),
-                                         state->function_name,
-                                         (gpointer *) &plugin_func);
-               if (!exists)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                state->function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
@@ -3443,18 +3434,18 @@ gs_plugin_loader_run (GsPluginLoader *plugin_loader, const gchar *function_name)
 {
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
        gboolean ret;
-       GsPluginFunc plugin_func = NULL;
        GsPlugin *plugin;
        guint i;
 
        /* run each plugin */
        for (i = 0; i < priv->plugins->len; i++) {
+               GsPluginFunc plugin_func = NULL;
                g_autoptr(AsProfileTask) ptask = NULL;
                plugin = g_ptr_array_index (priv->plugins, i);
-               ret = g_module_symbol (gs_plugin_get_module (plugin),
-                                      function_name,
-                                      (gpointer *) &plugin_func);
-               if (!ret)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
@@ -3901,10 +3892,10 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
                plugin = g_ptr_array_index (priv->plugins, i);
                if (!gs_plugin_get_enabled (plugin))
                        continue;
-               ret = g_module_symbol (gs_plugin_get_module (plugin),
-                                      function_name,
-                                      (gpointer *) &plugin_func);
-               if (!ret)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask2 = as_profile_start (priv->profile,
                                           "GsPlugin::%s(%s)",
@@ -4173,7 +4164,6 @@ gs_plugin_loader_run_refresh (GsPluginLoader *plugin_loader,
        gboolean anything_ran = FALSE;
        gboolean ret;
        guint i;
-       gboolean exists;
 
        /* run each plugin */
        for (i = 0; i < priv->plugins->len; i++) {
@@ -4187,10 +4177,10 @@ gs_plugin_loader_run_refresh (GsPluginLoader *plugin_loader,
                        return FALSE;
                }
 
-               exists = g_module_symbol (gs_plugin_get_module (plugin),
-                                         function_name,
-                                         (gpointer *) &plugin_func);
-               if (!exists)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
@@ -4349,13 +4339,12 @@ gs_plugin_loader_file_to_app_thread_cb (GTask *task,
                plugin = g_ptr_array_index (priv->plugins, i);
                if (!gs_plugin_get_enabled (plugin))
                        continue;
-               ret = g_task_return_error_if_cancelled (task);
-               if (ret)
+               if (g_task_return_error_if_cancelled (task))
                        return;
-               ret = g_module_symbol (gs_plugin_get_module (plugin),
-                                      function_name,
-                                      (gpointer *) &plugin_func);
-               if (!ret)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
@@ -4520,24 +4509,22 @@ gs_plugin_loader_update_thread_cb (GTask *task,
        gboolean ret = TRUE;
        GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
        GsPlugin *plugin;
-       GsPluginUpdateFunc plugin_func = NULL;
-       GsPluginActionFunc plugin_app_func = NULL;
        guint i;
 
        /* run each plugin */
        for (i = 0; i < priv->plugins->len; i++) {
+               GsPluginUpdateFunc plugin_func = NULL;
                g_autoptr(AsProfileTask) ptask = NULL;
                g_autoptr(GError) error_local = NULL;
                plugin = g_ptr_array_index (priv->plugins, i);
                if (!gs_plugin_get_enabled (plugin))
                        continue;
-               ret = g_task_return_error_if_cancelled (task);
-               if (ret)
+               if (g_task_return_error_if_cancelled (task))
                        return;
-               ret = g_module_symbol (gs_plugin_get_module (plugin),
-                                      function_name,
-                                      (gpointer *) &plugin_func);
-               if (!ret)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_func);
+               if (plugin_func == NULL)
                        continue;
                ptask = as_profile_start (priv->profile,
                                          "GsPlugin::%s(%s)",
@@ -4567,18 +4554,18 @@ gs_plugin_loader_update_thread_cb (GTask *task,
        /* run each plugin, per-app version */
        function_name = "gs_plugin_update_app";
        for (i = 0; i < priv->plugins->len; i++) {
+               GsPluginActionFunc plugin_app_func = NULL;
                guint j;
 
                plugin = g_ptr_array_index (priv->plugins, i);
                if (!gs_plugin_get_enabled (plugin))
                        continue;
-               ret = g_task_return_error_if_cancelled (task);
-               if (ret)
+               if (g_task_return_error_if_cancelled (task))
                        return;
-               ret = g_module_symbol (gs_plugin_get_module (plugin),
-                                      function_name,
-                                      (gpointer *) &plugin_app_func);
-               if (!ret)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &plugin_app_func);
+               if (plugin_app_func == NULL)
                        continue;
 
                /* for each app */
@@ -4673,18 +4660,17 @@ gs_plugin_loader_get_plugin_supported (GsPluginLoader *plugin_loader,
                                       const gchar *function_name)
 {
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
-       gboolean ret;
-       gpointer dummy;
        guint i;
 
        for (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;
-               ret = g_module_symbol (gs_plugin_get_module (plugin),
-                                      function_name,
-                                      (gpointer *) &dummy);
-               if (ret)
+               g_module_symbol (gs_plugin_get_module (plugin),
+                                function_name,
+                                (gpointer *) &dummy);
+               if (dummy != NULL)
                        return TRUE;
        }
        return FALSE;


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