From d1e5afed4ce5a0a0d67ecf2f6000745ebce2f0d5 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Thu, 20 Jun 2013 17:24:04 +0800 Subject: [PATCH] DBusString: fix may if try to free a uninitialized str If the str will be freed hasn't been initialized by _dbus_string_init correctly, _dbus_string_free may crash due to trying to free an undefined memory. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=65959 Signed-off-by: Chengwei Yang --- dbus/dbus-string.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index e3766aa..52eb0f2 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -246,6 +246,14 @@ _dbus_string_free (DBusString *str) if (real->constant) return; + + /* so it's safe if @p str returned by a failed + * _dbus_string_init call + * Bug: https://bugs.freedesktop.org/show_bug.cgi?id=65959 + */ + if (real->str == NULL) + return; + dbus_free (real->str - real->align_offset); real->invalid = TRUE; -- 1.7.9.5