summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2017-11-06 19:10:42 +0000
committerSimon McVittie <smcv@collabora.com>2017-11-07 11:43:34 +0000
commitd0008916245a74402272e7f490343acb579a7bbf (patch)
treeed6abbc656469aa2b4d92e5c86f3472b6a09b61e
parent208af9a447f3960db08083e1127d7389bdb711f2 (diff)
do_noncefile_create: Avoid freeing uninitialized memory on error
We could free all of these without having ever successfully initialized them. Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103597 (cherry picked from commit 6d08f5c04e601f16ef4ee2126a90c924b7e26df0)
-rw-r--r--dbus/dbus-nonce.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/dbus/dbus-nonce.c b/dbus/dbus-nonce.c
index 49f873693..7f3118cd8 100644
--- a/dbus/dbus-nonce.c
+++ b/dbus/dbus-nonce.c
@@ -280,6 +280,12 @@ do_noncefile_create (DBusNonceFile *noncefile,
_dbus_assert (noncefile);
+ /* Make it valid to "free" these even if _dbus_string_init() runs
+ * out of memory: see comment in do_check_nonce() */
+ _dbus_string_init_const (&randomStr, "");
+ _dbus_string_init_const (&noncefile->dir, "");
+ _dbus_string_init_const (&noncefile->path, "");
+
if (!_dbus_string_init (&randomStr))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);