dbus/dbus dbus-string.c,1.45,1.46 dbus-sysdeps.h,1.37,1.38
David Zeuthen
david@pdx.freedesktop.org
Fri, 05 Mar 2004 06:05:35 -0800
Update of /cvs/dbus/dbus/dbus
In directory pdx:/tmp/cvs-serv8744/dbus
Modified Files:
dbus-string.c dbus-sysdeps.h
Log Message:
2004-03-01 David Zeuthen <david@fubar.dk>
* dbus/dbus-string.c (_dbus_string_append_printf_valist): Fix a
bug where args were used twice. This bug resulted in a segfault
on a Debian/PPC system when starting the messagebus daemon. Include
dbus-sysdeps.h for DBUS_VA_COPY
* dbus/dbus-sysdeps.h: Define DBUS_VA_COPY if neccessary. From GLib
* configure.in: Check for va_copy; define DBUS_VA_COPY to the
appropriate va_copy implementation. From GLib
Index: dbus-string.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- a/dbus-string.c 2 Dec 2003 10:44:21 -0000 1.45
+++ b/dbus-string.c 5 Mar 2004 14:05:33 -0000 1.46
@@ -31,6 +31,8 @@
#define DBUS_CAN_USE_DBUS_STRING_PRIVATE 1
#include "dbus-string-private.h"
#include "dbus-protocol.h"
+/* for DBUS_VA_COPY */
+#include "dbus-sysdeps.h"
/**
* @defgroup DBusString string class
@@ -1013,16 +1015,26 @@
{
int len;
char c;
+ va_list args_copy;
+
DBUS_STRING_PREAMBLE (str);
-
+
+ DBUS_VA_COPY (args_copy, args);
+
/* Measure the message length without terminating nul */
len = vsnprintf (&c, 1, format, args);
if (!_dbus_string_lengthen (str, len))
- return FALSE;
-
+ {
+ /* don't leak the copy */
+ va_end (args_copy);
+ return FALSE;
+ }
+
vsprintf (real->str + (real->len - len),
- format, args);
+ format, args_copy);
+
+ va_end (args_copy);
return TRUE;
}
Index: dbus-sysdeps.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- a/dbus-sysdeps.h 2 Dec 2003 10:44:21 -0000 1.37
+++ b/dbus-sysdeps.h 5 Mar 2004 14:05:33 -0000 1.38
@@ -306,6 +306,20 @@
DBusSignalHandler handler);
+/* Define DBUS_VA_COPY() to do the right thing for copying va_list variables.
+ * config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy.
+ */
+#if !defined (DBUS_VA_COPY)
+# if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
+# define DBUS_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
+# elif defined (DBUS_VA_COPY_AS_ARRAY)
+# define DBUS_VA_COPY(ap1, ap2) memcpy ((ap1), (ap2), sizeof (va_list))
+# else /* va_list is a pointer */
+# define DBUS_VA_COPY(ap1, ap2) ((ap1) = (ap2))
+# endif /* va_list is a pointer */
+#endif /* !DBUS_VA_COPY */
+
+
DBUS_END_DECLS;
#endif /* DBUS_SYSDEPS_H */