DBusString: fix may crash if try to free an uninitialized str
authorChengwei Yang <chengwei.yang@intel.com>
Thu, 20 Jun 2013 09:24:04 +0000 (17:24 +0800)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Thu, 20 Jun 2013 12:16:25 +0000 (13:16 +0100)
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 <chengwei.yang@intel.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
dbus/dbus-string.c

index e3766aa..52eb0f2 100644 (file)
@@ -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;