42 lines
1.3 KiB
Diff
42 lines
1.3 KiB
Diff
From 8bfb572b5847e271fac49b24c9ceb1a5ea3bdf5d Mon Sep 17 00:00:00 2001
|
|
From: Benjamin Berg <bberg@redhat.com>
|
|
Date: Thu, 2 Jan 2020 18:38:19 +0100
|
|
Subject: [PATCH 161/181] examples: Fix possible use-after-free in storage code
|
|
|
|
The variant may need the buffer, so we should only free the buffer
|
|
together with the variant.
|
|
---
|
|
examples/storage.c | 9 +++++++--
|
|
1 file changed, 7 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/examples/storage.c b/examples/storage.c
|
|
index 6ca6efc..bb69305 100644
|
|
--- a/examples/storage.c
|
|
+++ b/examples/storage.c
|
|
@@ -57,7 +57,7 @@ load_data (void)
|
|
{
|
|
GVariantDict *res;
|
|
GVariant *var;
|
|
- g_autofree gchar *contents = NULL;
|
|
+ gchar *contents = NULL;
|
|
gsize length = 0;
|
|
|
|
if (!g_file_get_contents (STORAGE_FILE, &contents, &length, NULL))
|
|
@@ -66,7 +66,12 @@ load_data (void)
|
|
return g_variant_dict_new (NULL);
|
|
}
|
|
|
|
- var = g_variant_new_from_data (G_VARIANT_TYPE_VARDICT, contents, length, FALSE, NULL, NULL);
|
|
+ var = g_variant_new_from_data (G_VARIANT_TYPE_VARDICT,
|
|
+ contents,
|
|
+ length,
|
|
+ FALSE,
|
|
+ g_free,
|
|
+ contents);
|
|
|
|
res = g_variant_dict_new (var);
|
|
g_variant_unref (var);
|
|
--
|
|
2.24.1
|
|
|