Skip to content

Commit

Permalink
pk-offline-update: Fix crash due to invalid g_auto declaration in swi…
Browse files Browse the repository at this point in the history
…tch / case

'case PK_PROGRESS_TYPE_PERCENTAGE' is just a label and doesn't offer
any scope as such. So, 'tmp_perc' auto variable will be allocated in
the stack, but will not be initialized to 'NULL' for 'case:'
statements other than 'PK_PROGRESS_TYPE_PERCENTAGE', causing GLib to
consider the 'tmp_perc' garbage value as a valid memory address
allocated via 'g_malloc()', triggering an invalid 'free()' causing the
crash.

Rather than adding a scope '{}' within 'case', and causing a huge
noise in git diff, we just move the declaration to an upper scope.
  • Loading branch information
sidt4 authored and ximion committed Mar 23, 2024
1 parent 00e82be commit 3605809
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions client/pk-offline-update.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pk_offline_update_progress_cb (PkProgress *progress,
PkStatusEnum status;
gint percentage;
g_autofree gchar *msg = NULL;
g_autofree gchar *tmp_perc = NULL;
g_autoptr(PkPackage) pkg = NULL;

switch (type) {
Expand Down Expand Up @@ -145,8 +146,6 @@ pk_offline_update_progress_cb (PkProgress *progress,
pk_package_get_data (pkg));
break;
case PK_PROGRESS_TYPE_PERCENTAGE:
g_autofree gchar *tmp_perc = NULL;

g_object_get (progress, "percentage", &percentage, NULL);
if (percentage < 0)
return;
Expand Down

0 comments on commit 3605809

Please sign in to comment.