dbus-1.0.2 patches for hpux & others

Peter O'Gorman dbus at mlists.thewrittenword.com
Wed Jun 27 12:35:23 PDT 2007


Hi,
I know that the source has probably moved on since dbus-1.0.2, but
maybe some of these will still apply.

We had crashing issues with HP-UX, IRIX and Tru64 because their
vsnprintf is non-standard. Rather than returing the number of chars
that would have been copied had the buffer been big enough, hpux
returns -1, tru64 and irix return the number of chars actually copied
less one. 

Not all of our systems have strtoll and strtoull, so, on those systems
we used replacement funcs (very lightly modified from freebsd cvs).

configure checks for a c++ compiler but it is not used. added
AC_SYS_LARGEFILE to configure.in which makes
-D_POSIX_PTHREAD_SEMANTICS for solaris redundant. no need to push and
pop LANG(C). The test for va_copy by value was broken.

static const DBusTypeReaderClass const * has one too many consts.

AIX does not like enums with a final comma.

AIX sys/poll.h has a couple of #defines that break compilation, so we
need to #include its sys/poll.h before DBusPollFD is declared.

Patch attached.

Thanks,
Peter
-------------- next part --------------
Index: configure.in
===================================================================
--- configure.in.orig	2006-12-11 19:21:19.000000000 +0000
+++ configure.in	2007-06-27 17:09:53.342420685 +0000
 
 AC_PROG_CC
-AC_PROG_CXX
 AC_ISC_POSIX
 AC_HEADER_STDC
-
+AC_SYS_LARGEFILE
 AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests],[enable unit test code]),enable_tests=$enableval,enable_tests=$USE_MAINTAINER_MODE)
 AC_ARG_ENABLE(ansi, AS_HELP_STRING([--enable-ansi],[enable -ansi -pedantic gcc flags]),enable_ansi=$enableval,enable_ansi=no)
 AC_ARG_ENABLE(verbose-mode, AS_HELP_STRING([--enable-verbose-mode],[support verbose debug mode]),enable_verbose_mode=$enableval,enable_verbose_mode=$USE_MAINTAINER_MODE)
@@ -437,14 +275,12 @@
   AC_DEFINE_UNQUOTED(DBUS_VA_COPY,$dbus_va_copy_func,[A 'va_copy' style function])
 fi
 
-AC_LANG_PUSH(C)
 AC_CACHE_CHECK([whether va_lists can be copied by value],
 	dbus_cv_va_val_copy,
 	[AC_RUN_IFELSE([AC_LANG_PROGRAM(
 [[
 	#include <stdarg.h>
-]],
-[[
+
 	void f (int i, ...) {
 	va_list args1, args2;
 	va_start (args1, i);
@@ -453,16 +289,15 @@
 	  exit (1);
 	va_end (args1); va_end (args2);
 	}
-	int main() {
+
+]],
+[[
 	  f (0, 42);
-	  return 0;
-	}
 ]])],
 	[dbus_cv_va_val_copy=yes],
 	[dbus_cv_va_val_copy=no],
 	[dbus_cv_va_val_copy=yes])
 ])
-AC_LANG_POP(C)
 
 if test "x$dbus_cv_va_val_copy" = "xno"; then
   AC_DEFINE(DBUS_VA_COPY_AS_ARRAY,1, ['va_lists' cannot be copies as values])
@@ -525,7 +360,7 @@
 AC_CHECK_FUNC(gethostbyname,,[AC_CHECK_LIB(nsl,gethostbyname)])
 
 AC_CHECK_FUNCS(vsnprintf vasprintf nanosleep usleep poll setenv unsetenv socketpair getgrouplist fpathconf)
-
+AC_REPLACE_FUNCS(strtoll strtoull)
 AC_MSG_CHECKING(for dirfd)
 AC_TRY_LINK([
 #include <sys/types.h>
@@ -561,14 +398,13 @@
 
 AC_CHECK_HEADERS(execinfo.h, [AC_CHECK_FUNCS(backtrace)])
 
-AC_CHECK_HEADERS(errno.h)
+AC_CHECK_HEADERS(errno.h sys/select.h)
 
 # checking for a posix version of getpwnam_r
 # if we are cross compiling and can not run the test
 # assume getpwnam_r is the posix version
 # it is up to the person cross compiling to change
 # this behavior if desired
-AC_LANG_PUSH(C)
 AC_CACHE_CHECK([for posix getpwnam_r],
 		ac_cv_func_posix_getpwnam_r,
 		[AC_RUN_IFELSE([AC_LANG_PROGRAM(
@@ -590,7 +426,6 @@
 	[ac_cv_func_posix_getpwnam_r=no],
         [ac_cv_func_posix_getpwnam_r=yes]
 )])
-AC_LANG_POP(C)
 
 if test "$ac_cv_func_posix_getpwnam_r" = yes; then
 	AC_DEFINE(HAVE_POSIX_GETPWNAM_R,1,
@@ -679,7 +514,6 @@
 
 #### Abstract sockets
 
-AC_LANG_PUSH(C)
 AC_CACHE_CHECK([abstract socket namespace],
 		ac_cv_have_abstract_sockets,
 		[AC_RUN_IFELSE([AC_LANG_PROGRAM(
@@ -721,7 +555,6 @@
               [ac_cv_have_abstract_sockets=yes],
               [ac_cv_have_abstract_sockets=no]
 )])
-AC_LANG_POP(C)
 
 if test x$enable_abstract_sockets = xyes; then
     if test x$ac_cv_have_abstract_sockets = xno; then
@@ -1240,7 +1056,6 @@
 	compiler:		  ${CC}
 	cflags:		          ${CFLAGS}
 	cppflags:		  ${CPPFLAGS}
-	cxxflags:		  ${CXXFLAGS}
 	64-bit int:		  ${DBUS_INT64_TYPE}
 	32-bit int:		  ${DBUS_INT32_TYPE}
 	16-bit int:		  ${DBUS_INT16_TYPE}
 
Index: tools/Makefile.am
===================================================================
--- tools/Makefile.am.orig	2006-12-11 19:21:26.000000000 +0000
+++ tools/Makefile.am	2007-06-25 16:20:06.459066197 +0000
@@ -25,7 +25,7 @@
 dbus_uuidgen_SOURCES=				\
 	dbus-uuidgen.c
 
-dbus_send_LDADD= $(top_builddir)/dbus/libdbus-1.la $(DBUS_CLIENT_LIBS)
+dbus_send_LDADD= $(top_builddir)/dbus/libdbus-1.la $(DBUS_CLIENT_LIBS) $(LIBOBJS)
 dbus_send_LDFLAGS=@R_DYNAMIC_LDFLAG@
 
 dbus_monitor_LDADD= $(top_builddir)/dbus/libdbus-1.la $(DBUS_CLIENT_LIBS)
Index: dbus/dbus-sysdeps-unix.c
===================================================================
--- dbus/dbus-sysdeps-unix.c.orig	2006-12-11 19:21:09.000000000 +0000
+++ dbus/dbus-sysdeps-unix.c	2007-06-27 18:06:14.559080812 +0000
@@ -83,7 +87,7 @@
                    DBusError        *error)
 {
   *fd = socket (domain, type, protocol);
-  if (fd >= 0)
+  if (*fd >= 0)
     {
       return TRUE;
     }
@@ -2312,7 +2316,25 @@
                                  va_list     args)
 {
   char c;
-  return vsnprintf (&c, 1, format, args);
+  int err = vsnprintf (&c, 1, format, args);
+/* The above causes HP-UX's vsnprintf to return -1, because the string
+ * did not fit, it causes IRIX and Tru64 to return the number of
+ * characters actually copied minus the terminating NULL (i.e. 0),
+ * neither of these are the desired result, so we've got to be a
+ * little more careful */ 
+  if (err <= 0)
+  {
+    char *y;
+    int alloc_size=1024;
+	do {
+	  y = malloc(alloc_size);
+	  err = vsnprintf (y, alloc_size, format, args);
+      free(y);
+	  if ((err <0 ) || (err == (alloc_size-1))) err = 0;
+	  alloc_size++;
+	} while ((err == 0) && (alloc_size < 1024*640));
+  }
+  return err; 
 }
 
 /**
Index: dbus/dbus-marshal-recursive.c
===================================================================
--- dbus/dbus-marshal-recursive.c.orig	2006-12-11 19:21:06.000000000 +0000
+++ dbus/dbus-marshal-recursive.c	2007-06-23 20:26:00.181195234 +0000
@@ -690,7 +690,7 @@
   base_reader_next
 };
 
-static const DBusTypeReaderClass const *
+static const DBusTypeReaderClass *
 all_reader_classes[] = {
   &body_reader_class,
   &body_types_only_reader_class,
Index: dbus/dbus-sysdeps.h
===================================================================
--- dbus/dbus-sysdeps.h.orig	2006-12-11 19:21:16.000000000 +0000
+++ dbus/dbus-sysdeps.h	2007-06-23 21:21:19.474185054 +0000
@@ -39,6 +38,14 @@
 
 #include <stdarg.h>
 
+/* AIX sys/poll.h does #define events reqevents, and other
+ * wonderousness, so must include sys/poll before declaring
+ * DBusPollFD
+ */ 
+#ifdef HAVE_POLL
+#include <sys/poll.h>
+#endif
+
 DBUS_BEGIN_DECLS
 
 /* Forward declarations */
Index: dbus/dbus-internals.c
===================================================================
--- dbus/dbus-internals.c.orig	2006-12-11 19:21:06.000000000 +0000
+++ dbus/dbus-internals.c	2007-06-25 15:33:24.985099807 +0000
@@ -295,7 +295,7 @@
 #include <pthread.h>
 #endif
 
-static inline void
+static void
 _dbus_verbose_init (void)
 {
   if (!verbose_initted)
Index: tools/dbus-monitor.c
===================================================================
--- tools/dbus-monitor.c.orig	2006-12-11 19:21:25.000000000 +0000
+++ tools/dbus-monitor.c	2007-06-25 20:29:02.919559058 +0000
@@ -61,7 +67,7 @@
   PROFILE_ATTRIBUTE_FLAG_PATH = 16,
   PROFILE_ATTRIBUTE_FLAG_INTERFACE = 32,
   PROFILE_ATTRIBUTE_FLAG_MEMBER = 64,
-  PROFILE_ATTRIBUTE_FLAG_ERROR_NAME = 128,
+  PROFILE_ATTRIBUTE_FLAG_ERROR_NAME = 128
 } ProfileAttributeFlags;
 
 static void
Index: tools/strtoll.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ tools/strtoll.c	2007-06-25 19:25:52.135530071 +0000
@@ -0,0 +1,146 @@
+/*-
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* Minimum and maximum values a `signed long long int' can hold.  */
+#ifndef LLONG_MAX
+#   define LLONG_MAX	9223372036854775807LL
+#endif
+
+#ifndef LLONG_MIN
+#   define LLONG_MIN	(-LLONG_MAX - 1LL)
+#endif
+/* Maximum value an `unsigned long long int' can hold.  (Minimum is 0.)  */
+#ifndef ULLONG_MAX
+#   define ULLONG_MAX	18446744073709551615ULL
+#endif
+/*
+ * Convert a string to a long long integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+long long
+strtoll(const char * nptr, char ** endptr, int base)
+{
+	const char *s;
+	unsigned long long acc;
+	char c;
+	unsigned long long cutoff;
+	int neg, any, cutlim;
+
+	/*
+	 * Skip white space and pick up leading +/- sign if any.
+	 * If base is 0, allow 0x for hex and 0 for octal, else
+	 * assume decimal; if base is already 16, allow 0x.
+	 */
+	s = nptr;
+	do {
+		c = *s++;
+	} while (isspace((unsigned char)c));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X') &&
+	    ((s[1] >= '0' && s[1] <= '9') ||
+	    (s[1] >= 'A' && s[1] <= 'F') ||
+	    (s[1] >= 'a' && s[1] <= 'f'))) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	/*
+	 * Compute the cutoff value between legal numbers and illegal
+	 * numbers.  That is the largest legal value, divided by the
+	 * base.  An input number that is greater than this value, if
+	 * followed by a legal input character, is too big.  One that
+	 * is equal to this value may be valid or not; the limit
+	 * between valid and invalid numbers is then based on the last
+	 * digit.  For instance, if the range for quads is
+	 * [-9223372036854775808..9223372036854775807] and the input base
+	 * is 10, cutoff will be set to 922337203685477580 and cutlim to
+	 * either 7 (neg==0) or 8 (neg==1), meaning that if we have
+	 * accumulated a value > 922337203685477580, or equal but the
+	 * next digit is > 7 (or 8), the number is too big, and we will
+	 * return a range error.
+	 *
+	 * Set 'any' if any `digits' consumed; make it negative to indicate
+	 * overflow.
+	 */
+	cutoff = neg ? (unsigned long long)-(LLONG_MIN + LLONG_MAX) + LLONG_MAX
+	    : LLONG_MAX;
+	cutlim = cutoff % base;
+	cutoff /= base;
+	for ( ; ; c = *s++) {
+		if (c >= '0' && c <= '9')
+			c -= '0';
+		else if (c >= 'A' && c <= 'Z')
+			c -= 'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = neg ? LLONG_MIN : LLONG_MAX;
+		errno = ERANGE;
+	} else if (!any) {
+noconv:
+		errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (char *)(any ? s - 1 : nptr);
+	return (acc);
+}
Index: tools/strtoull.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ tools/strtoull.c	2007-06-25 19:25:44.064748595 +0000
@@ -0,0 +1,125 @@
+/*-
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* Minimum and maximum values a `signed long long int' can hold.  */
+#ifndef LLONG_MAX
+#   define LLONG_MAX	9223372036854775807LL
+#endif
+
+#ifndef LLONG_MIN
+#   define LLONG_MIN	(-LLONG_MAX - 1LL)
+#endif
+/* Maximum value an `unsigned long long int' can hold.  (Minimum is 0.)  */
+#ifndef ULLONG_MAX
+#   define ULLONG_MAX	18446744073709551615ULL
+#endif
+
+/*
+ * Convert a string to an unsigned long long integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+unsigned long long
+strtoull(const char * nptr, char ** endptr, int base)
+{
+	const char *s;
+	unsigned long long acc;
+	char c;
+	unsigned long long cutoff;
+	int neg, any, cutlim;
+
+	/*
+	 * See strtoq for comments as to the logic used.
+	 */
+	s = nptr;
+	do {
+		c = *s++;
+	} while (isspace((unsigned char)c));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X') &&
+	    ((s[1] >= '0' && s[1] <= '9') ||
+	    (s[1] >= 'A' && s[1] <= 'F') ||
+	    (s[1] >= 'a' && s[1] <= 'f'))) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	cutoff = ULLONG_MAX / base;
+	cutlim = ULLONG_MAX % base;
+	for ( ; ; c = *s++) {
+		if (c >= '0' && c <= '9')
+			c -= '0';
+		else if (c >= 'A' && c <= 'Z')
+			c -= 'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = ULLONG_MAX;
+		errno = ERANGE;
+	} else if (!any) {
+noconv:
+		errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (char *)(any ? s - 1 : nptr);
+	return (acc);
+}
Index: tools/dbus-launch.c
===================================================================
--- tools/dbus-launch.c.orig	2006-12-11 19:21:25.000000000 +0000
+++ tools/dbus-launch.c	2007-06-25 16:26:52.391252325 +0000
@@ -32,7 +32,9 @@
 #include <string.h>
 #include <signal.h>
 #include <stdarg.h>
+#if HAVE_SYS_SELECT_H
 #include <sys/select.h>
+#endif
 #include <time.h>
 
 #ifdef DBUS_BUILD_X11
Index: dbus/dbus-shell.c
===================================================================
--- dbus/dbus-shell.c.orig	2006-12-11 19:21:08.000000000 +0000
+++ dbus/dbus-shell.c	2007-06-25 20:28:52.007410910 +0000
@@ -22,7 +22,6 @@
  *
  */
 
-#include <string.h>
 #include "dbus-internals.h"
 #include "dbus-list.h"
 #include "dbus-memory.h"
@@ -30,6 +29,7 @@
 #include "dbus-shell.h"
 #include "dbus-string.h"
 
+#include <string.h>
 /* Single quotes preserve the literal string exactly. escape
  * sequences are not allowed; not even \' - if you want a '
  * in the quoted text, you have to do something like 'foo'\''bar'
Index: dbus/dbus-string.c
===================================================================
--- dbus/dbus-string.c.orig	2006-12-11 19:21:13.000000000 +0000
+++ dbus/dbus-string.c	2007-06-26 19:52:38.112860600 +0000
@@ -1201,7 +1201,12 @@
 
   /* Measure the message length without terminating nul */
   len = _dbus_printf_string_upper_bound (format, args);
-
+  if (!len)
+	{
+      /* don't leak the copy */
+      va_end (args_copy);
+      return FALSE;
+	}
   if (!_dbus_string_lengthen (str, len))
     {
       /* don't leak the copy */


More information about the dbus mailing list