[gnome-software/1648-crash-on-packagekit-app-install: 10/10] PackageKit: Change app_list_get_package_ids() to never NULL-terminate the array
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1648-crash-on-packagekit-app-install: 10/10] PackageKit: Change app_list_get_package_ids() to never NULL-terminate the array
- Date: Thu, 17 Feb 2022 12:38:19 +0000 (UTC)
commit dd1159dd1ffb7807419175802a903f2adcc9491f
Author: Milan Crha <mcrha redhat com>
Date: Thu Feb 17 13:35:25 2022 +0100
PackageKit: Change app_list_get_package_ids() to never NULL-terminate the array
Let the caller NULL-terminate the array, because if the caller adds
more packages at the end of the array, the added items would be after
this NULL, thus not noticed by the PackageKit.
plugins/packagekit/gs-plugin-packagekit.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index 56ddb1ccc..71b4d6553 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -280,7 +280,7 @@ typedef gboolean (*GsAppFilterFunc) (GsApp *app);
/* The elements in the returned #GPtrArray reference memory from within the
* @apps list, so the array is only valid as long as @apps is not modified or
- * freed. */
+ * freed. The array is not NULL-terminated. */
static GPtrArray *
app_list_get_package_ids (GsAppList *apps,
GsAppFilterFunc app_filter,
@@ -307,9 +307,6 @@ app_list_get_package_ids (GsAppList *apps,
}
}
- if (list_package_ids->len > 0)
- g_ptr_array_add (list_package_ids, NULL);
-
return g_steal_pointer (&list_package_ids);
}
@@ -612,6 +609,7 @@ gs_plugin_app_install (GsPlugin *plugin,
return FALSE;
}
+ /* NULL-terminate the array */
g_ptr_array_add (array_package_ids, NULL);
gs_app_set_state (app, GS_APP_STATE_INSTALLING);
@@ -1673,6 +1671,9 @@ gs_plugin_packagekit_refine_async (GsPlugin *plugin,
package_ids = app_list_get_package_ids (details_list, NULL, FALSE);
if (package_ids->len > 0) {
+ /* NULL-terminate the array */
+ g_ptr_array_add (package_ids, NULL);
+
/* get any details */
g_mutex_lock (&self->client_mutex_refine);
pk_client_set_interactive (self->client_refine, gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
@@ -1942,7 +1943,10 @@ get_details_cb (GObject *source_object,
if (!gs_plugin_packagekit_results_valid (results, &local_error)) {
g_autoptr(GPtrArray) package_ids = app_list_get_package_ids (data->details_list, NULL, FALSE);
- g_autofree gchar *package_ids_str = g_strjoinv (",", (gchar **) package_ids->pdata);
+ g_autofree gchar *package_ids_str = NULL;
+ /* NULL-terminate the array */
+ g_ptr_array_add (package_ids, NULL);
+ package_ids_str = g_strjoinv (",", (gchar **) package_ids->pdata);
g_prefix_error (&local_error, "failed to get details for %s: ",
package_ids_str);
refine_task_complete_operation_with_error (refine_task, g_steal_pointer (&local_error));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]