gdbus: Fix crash in g_dbus_create_error_valist
authorSzymon Janc <szymon.janc@tieto.com>
Tue, 7 Apr 2015 20:07:41 +0000 (22:07 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 9 Apr 2015 14:59:08 +0000 (16:59 +0200)
Passing NULL format parameter to vsnprintf results in invalid argument
error on glibc. But with some other libc libraries (musl and uClibc)
this results in dereferencing NULL pointer and crash due to
segmentation fault.

gdbus/object.c

index 0f42dadf3e3ad041aef99f62843993ff30d446b9..96db5166530121b308cb50b426153569c35751c1 100644 (file)
@@ -1412,7 +1412,10 @@ DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
 {
        char str[1024];
 
-       vsnprintf(str, sizeof(str), format, args);
+       if (format)
+               vsnprintf(str, sizeof(str), format, args);
+       else
+               str[0] = '\0';
 
        return dbus_message_new_error(message, name, str);
 }