Merge branch 'dbus-1.10'
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 19 Oct 2015 15:52:08 +0000 (16:52 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 19 Oct 2015 15:52:08 +0000 (16:52 +0100)
15 files changed:
NEWS
bus/activation.c
bus/config-parser.c
bus/main.c
cmake/CMakeLists.txt
configure.ac
dbus/dbus-marshal-basic.c
dbus/dbus-marshal-recursive-util.c
dbus/dbus-sysdeps-util-unix.c
dbus/dbus-sysdeps-util-win.c
dbus/dbus-sysdeps-win.c
dbus/dbus-sysdeps-win.h
dbus/dbus-sysdeps.h
test/manual-paths.c
tools/dbus-print-message.c

diff --git a/NEWS b/NEWS
index 0e3c4d1..39cf1cb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,11 @@
-D-Bus 1.10.2 (UNRELEASED)
+D-Bus 1.11.0 (UNRELEASED)
 ==
 
+Dependencies:
+
+• On non-Windows platforms, D-Bus requires an <inttypes.h> that defines
+  C99 constants such as PRId64 and PRIu64.
+
 Fixes:
 
 • Correct error handling for activation: if there are multiple attempts
@@ -13,8 +18,15 @@ Fixes:
   This was not exploitable as a denial of service, because the check
   for a privileged user is done first. (fd.o #92298, Simon McVittie)
 
+• Print 64-bit integers on non-GNU Unix platforms (fd.o #92043, Natanael Copa)
+
 • On Windows, fix the logic for replacing the installation prefix
-  in service files' Exec lines (fd.o #83539; Milan Crha, Simon McVittie)
+  in service files' Exec lines, and the corresponding regression test
+  (fd.o #83539; Milan Crha, Simon McVittie)
+
+• On Windows, when including configuration files with <include> or
+  <includedir>, apply the same relocation as for the Exec paths
+  in .service files (fd.o #92028, Simon McVittie)
 
 • On Windows, if installed in the conventional layout with ${prefix}/etc
   and ${prefix}/share, use relative paths between bus configuration files
index 3c3bd7a..bf79f45 100644 (file)
@@ -261,6 +261,7 @@ update_desktop_file_entry (BusActivation       *activation,
   DBusString file_path;
   DBusError tmp_error;
   dbus_bool_t retval;
+  DBusString str;
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
@@ -308,9 +309,18 @@ update_desktop_file_entry (BusActivation       *activation,
                                     error))
     goto out;
 
-  exec = _dbus_strdup (_dbus_replace_install_prefix (exec_tmp));
-  dbus_free (exec_tmp);
-  exec_tmp = NULL;
+  if (!_dbus_string_init (&str))
+    goto out;
+
+  if (!_dbus_string_append (&str, exec_tmp) ||
+      !_dbus_replace_install_prefix (&str) ||
+      !_dbus_string_steal_data (&str, &exec))
+    {
+      _dbus_string_free (&str);
+      goto out;
+    }
+
+  _dbus_string_free (&str);
 
   /* user is not _required_ unless we are using system activation */
   if (!bus_desktop_file_get_string (desktop_file,
@@ -466,6 +476,7 @@ update_desktop_file_entry (BusActivation       *activation,
 
 out:
   /* if these have been transferred into entry, the variables will be NULL */
+  dbus_free (exec_tmp);
   dbus_free (name);
   dbus_free (exec);
   dbus_free (user);
index 3f59730..15ce8ff 100644 (file)
@@ -2122,7 +2122,8 @@ make_full_path (const DBusString *basedir,
 {
   if (_dbus_path_is_absolute (filename))
     {
-      return _dbus_string_copy (filename, 0, full_path, 0);
+      if (!_dbus_string_copy (filename, 0, full_path, 0))
+        return FALSE;
     }
   else
     {
@@ -2131,9 +2132,12 @@ make_full_path (const DBusString *basedir,
       
       if (!_dbus_concat_dir_and_file (full_path, filename))
         return FALSE;
-
-      return TRUE;
     }
+
+  if (!_dbus_replace_install_prefix (full_path))
+    return FALSE;
+
+  return TRUE;
 }
 
 static dbus_bool_t
@@ -3402,17 +3406,21 @@ test_default_session_servicedirs (void)
   DBusList *link;
   DBusString progs;
   int i;
+  dbus_bool_t ret = FALSE;
 
 #ifdef DBUS_WIN
   const char *common_progs;
-  char buffer[1024];
+  DBusString install_root_based;
+
+  if (!_dbus_string_init (&install_root_based) ||
+      !_dbus_string_append (&install_root_based, DBUS_DATADIR) ||
+      !_dbus_replace_install_prefix (&install_root_based))
+    _dbus_assert_not_reached ("OOM getting relocated DBUS_DATADIR");
+
+  _dbus_assert (_dbus_path_is_absolute (&install_root_based));
+
+  test_session_service_dir_matches[0] = _dbus_string_get_const_data (&install_root_based);
 
-  if (_dbus_get_install_root(buffer, sizeof(buffer)))
-    {
-      strcat(buffer,DBUS_DATADIR);
-      strcat(buffer,"/dbus-1/services");
-      test_session_service_dir_matches[0] = buffer;
-    }
 #endif
 
   /* On Unix we don't actually use this variable, but it's easier to handle the
@@ -3426,16 +3434,11 @@ test_default_session_servicedirs (void)
   if (common_progs) 
     {
       if (!_dbus_string_append (&progs, common_progs)) 
-        {
-          _dbus_string_free (&progs);
-          return FALSE;
-        }
+        goto out;
 
       if (!_dbus_string_append (&progs, "/dbus-1/services")) 
-        {
-          _dbus_string_free (&progs);
-          return FALSE;
-        }
+        goto out;
+
       test_session_service_dir_matches[1] = _dbus_string_get_const_data(&progs);
     }
 #endif
@@ -3457,8 +3460,7 @@ test_default_session_servicedirs (void)
           printf ("error with default session service directories\n");
              dbus_free (link->data);
          _dbus_list_free_link (link);
-          _dbus_string_free (&progs);
-          return FALSE;
+          goto out;
         }
  
       dbus_free (link->data);
@@ -3485,8 +3487,7 @@ test_default_session_servicedirs (void)
           printf ("more directories parsed than in match set\n");
           dbus_free (link->data);
           _dbus_list_free_link (link);
-          _dbus_string_free (&progs);
-          return FALSE;
+          goto out;
         }
  
       if (strcmp (test_session_service_dir_matches[i], 
@@ -3497,8 +3498,7 @@ test_default_session_servicedirs (void)
                   test_session_service_dir_matches[i]);
           dbus_free (link->data);
           _dbus_list_free_link (link);
-          _dbus_string_free (&progs);
-          return FALSE;
+          goto out;
         }
 
       ++i;
@@ -3511,13 +3511,17 @@ test_default_session_servicedirs (void)
     {
       printf ("extra data %s in the match set was not matched\n",
               test_session_service_dir_matches[i]);
-
-      _dbus_string_free (&progs);
-      return FALSE;
+      goto out;
     }
-    
+
+  ret = TRUE;
+
+out:
   _dbus_string_free (&progs);
-  return TRUE;
+#ifdef DBUS_WIN
+  _dbus_string_free (&install_root_based);
+#endif
+  return ret;
 }
 
 static const char *test_system_service_dir_matches[] = 
index ee5e1eb..612b4a6 100644 (file)
@@ -440,14 +440,14 @@ main (int argc, char **argv)
         {
           check_two_config_files (&config_file, "system");
 
-          if (!_dbus_append_system_config_file (&config_file))
+          if (!_dbus_get_system_config_file (&config_file))
             exit (1);
         }
       else if (strcmp (arg, "--session") == 0)
         {
           check_two_config_files (&config_file, "session");
 
-          if (!_dbus_append_session_config_file (&config_file))
+          if (!_dbus_get_session_config_file (&config_file))
             exit (1);
         }
       else if (strstr (arg, "--config-file=") == arg)
index 4db9c67..4bde279 100644 (file)
@@ -61,23 +61,6 @@ else (DBUS_INSTALL_DIR)
        set(DBUS_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}")
 endif (DBUS_INSTALL_DIR)
 
-# autotools style
-if (NOT DATAROOTDIR)
-    set (DATAROOTDIR share)
-endif()
-
-if (NOT DATADIR)
-    set (DATADIR ${DATAROOTDIR})
-endif()
-
-if (NOT DOCDIR)
-    SET(DOCDIR ${DATAROOTDIR}/doc/dbus)
-endif()
-
-if (NOT DBUS_DATADIR)
-    SET(DBUS_DATADIR ${DATADIR})
-endif()
-
 set(DBUS_PREFIX ${DBUS_INSTALL_DIR})
 
 set(prefix                   ${DBUS_INSTALL_DIR})
@@ -87,7 +70,7 @@ set(EXPANDED_INCLUDEDIR      ${DBUS_INSTALL_DIR}/include)
 set(EXPANDED_BINDIR          ${DBUS_INSTALL_DIR}/bin)
 set(EXPANDED_SYSCONFDIR      ${DBUS_INSTALL_DIR}/etc)
 set(EXPANDED_LOCALSTATEDIR   ${DBUS_INSTALL_DIR}/var)
-set(EXPANDED_DATADIR         ${DBUS_INSTALL_DIR}/${DBUS_DATADIR})
+set(EXPANDED_DATADIR         ${DBUS_INSTALL_DIR}/share)
 set(DBUS_MACHINE_UUID_FILE   ${DBUS_INSTALL_DIR}/lib/dbus/machine-id)
 set(DBUS_BINDIR              ${EXPANDED_BINDIR})
 set(DBUS_DAEMONDIR           ${EXPANDED_BINDIR})
@@ -106,6 +89,7 @@ set(SYSCONFDIR_FROM_PKGDATADIR ${EXPANDED_SYSCONFDIR})
 set(DATADIR_FROM_PKGSYSCONFDIR ${EXPANDED_DATADIR})
 endif()
 
+# used in the C code
 set(DBUS_LIBEXECDIR          ${EXPANDED_LIBDIR})
 set(DBUS_DATADIR             ${EXPANDED_DATADIR})
 
index da14b70..6078ce7 100644 (file)
@@ -3,7 +3,7 @@ AC_PREREQ([2.63])
 
 m4_define([dbus_major_version], [1])
 m4_define([dbus_minor_version], [10])
-m4_define([dbus_micro_version], [1])
+m4_define([dbus_micro_version], [99])
 m4_define([dbus_version],
           [dbus_major_version.dbus_minor_version.dbus_micro_version])
 AC_INIT([dbus],[dbus_version],[https://bugs.freedesktop.org/enter_bug.cgi?product=dbus],[dbus])
@@ -337,31 +337,6 @@ if test x$enable_compiler_coverage = xyes; then
      AC_DEFINE_UNQUOTED(DBUS_GCOV_ENABLED, 1, [Defined if gcov is enabled to force a rebuild due to config.h changing])
 fi
 
-# glibc21.m4 serial 3
-dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-
-# Test for the GNU C Library, version 2.1 or newer.
-# From Bruno Haible.
-
-AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer,
-  ac_cv_gnu_library_2_1,
-  [AC_EGREP_CPP([Lucky GNU user],
-    [
-#include <features.h>
-#ifdef __GNU_LIBRARY__
- #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2)
-  Lucky GNU user
- #endif
-#endif
-    ],
-    ac_cv_gnu_library_2_1=yes,
-    ac_cv_gnu_library_2_1=no)
-  ]
-)
-
 #### Integer sizes
 
 AC_CHECK_SIZEOF(char)
@@ -380,32 +355,21 @@ $ac_cv_sizeof_int)
   dbusint64=int
   dbusint64_constant='(val)'
   dbusuint64_constant='(val)'
-  dbusint64_printf_modifier='""'
   ;;
 $ac_cv_sizeof_long)
   dbusint64=long
   dbusint64_constant='(val##L)'
   dbusuint64_constant='(val##UL)'
-  dbusint64_printf_modifier='"l"'
   ;;
 $ac_cv_sizeof_long_long)
   dbusint64='long long'
   dbusint64_constant='(val##LL)'
   dbusuint64_constant='(val##ULL)'
-  # Ideally we discover what the format is, but this is
-  # only used in verbose mode, so eh...
-  if test x"$ac_cv_gnu_library_2_1" = xyes; then
-    dbusint64_printf_modifier='"ll"'
-  fi
   ;;
 $ac_cv_sizeof___int64)
   dbusint64=__int64
   dbusint64_constant='(val##i64)'
   dbusuint64_constant='(val##ui64)'
-  # See above case
-  if test x"$ac_cv_gnu_library_2_1" = xyes; then
-    dbusint64_printf_modifier='"ll"'
-  fi
   ;;
 esac
 
@@ -423,9 +387,6 @@ Please report a bug here with details of your platform and compiler:
         DBUS_INT64_TYPE="$dbusint64"
         DBUS_INT64_CONSTANT="$dbusint64_constant"
         DBUS_UINT64_CONSTANT="$dbusuint64_constant"
-       if test x"$dbusint64_printf_modifier" != x; then
-               AC_DEFINE_UNQUOTED(DBUS_INT64_PRINTF_MODIFIER, [$dbusint64_printf_modifier], [Define to printf modifier for 64 bit integer type])
-       fi
         AC_MSG_RESULT($DBUS_INT64_TYPE)
   ])
 
index 74fe3f9..855c869 100644 (file)
 
 #include <string.h>
 
+#if !defined(PRIx64) && defined(DBUS_WIN)
+#define PRIx64 "I64x"
+#endif
+
 #if defined(__GNUC__) && (__GNUC__ >= 4)
 # define _DBUS_ASSERT_ALIGNMENT(type, op, val) \
   _DBUS_STATIC_ASSERT (__extension__ __alignof__ (type) op val)
@@ -1334,10 +1338,8 @@ _dbus_verbose_bytes (const unsigned char *data,
           if (i > 7 &&
               _DBUS_ALIGN_ADDRESS (&data[i], 8) == &data[i])
             {
-#ifdef DBUS_INT64_PRINTF_MODIFIER
-              _dbus_verbose (" u64: 0x%" DBUS_INT64_PRINTF_MODIFIER "x",
+              _dbus_verbose (" u64: 0x%" PRIx64,
                              *(dbus_uint64_t*)&data[i-8]);
-#endif
               _dbus_verbose (" dbl: %g",
                              *(double*)&data[i-8]);
             }
index 3bc26a8..309da26 100644 (file)
 #include "dbus-internals.h"
 #include <string.h>
 
+#if !defined(PRIx64) && defined(DBUS_WIN)
+#define PRIx64 "I64x"
+#endif
+
 static void
 basic_value_zero (DBusBasicValue *value)
 {
@@ -2644,12 +2648,10 @@ double_read_value (TestTypeNode   *node,
 
   if (!_DBUS_DOUBLES_BITWISE_EQUAL (v, expected))
     {
-#ifdef DBUS_INT64_PRINTF_MODIFIER
-      _dbus_warn ("Expected double %g got %g\n bits = 0x%" DBUS_INT64_PRINTF_MODIFIER "x vs.\n bits = 0x%" DBUS_INT64_PRINTF_MODIFIER "x)\n",
+      _dbus_warn ("Expected double %g got %g\n bits = 0x%" PRIx64 " vs.\n bits = 0x%" PRIx64 ")\n",
                   expected, v,
                   *(dbus_uint64_t*)(char*)&expected,
                   *(dbus_uint64_t*)(char*)&v);
-#endif
       _dbus_assert_not_reached ("test failed");
     }
 
index 9b724cc..9d22069 100644 (file)
@@ -1272,17 +1272,18 @@ fail:
   return FALSE;
 }
 
-/*
- * replaces the term DBUS_PREFIX in configure_time_path by the
- * current dbus installation directory. On unix this function is a noop
+/**
+ * Replace the DBUS_PREFIX in the given path, in-place, by the
+ * current D-Bus installation directory. On Unix this function
+ * does nothing, successfully.
  *
- * @param configure_time_path
- * @return real path
+ * @param path path to edit
+ * @return #FALSE on OOM
  */
-const char *
-_dbus_replace_install_prefix (const char *configure_time_path)
+dbus_bool_t
+_dbus_replace_install_prefix (DBusString *path)
 {
-  return configure_time_path;
+  return TRUE;
 }
 
 #define DBUS_UNIX_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
@@ -1424,27 +1425,31 @@ _dbus_get_standard_system_servicedirs (DBusList **dirs)
 }
 
 /**
- * Append the absolute path of the system.conf file
+ * Get the absolute path of the system.conf file
  * (there is no system bus on Windows so this can just
  * return FALSE and print a warning or something)
  *
- * @param str the string to append to
+ * @param str the string to append to, which must be empty on entry
  * @returns #FALSE if no memory
  */
 dbus_bool_t
-_dbus_append_system_config_file (DBusString *str)
+_dbus_get_system_config_file (DBusString *str)
 {
+  _dbus_assert (_dbus_string_get_length (str) == 0);
+
   return _dbus_string_append (str, DBUS_SYSTEM_CONFIG_FILE);
 }
 
 /**
- * Append the absolute path of the session.conf file.
+ * Get the absolute path of the session.conf file.
  *
- * @param str the string to append to
+ * @param str the string to append to, which must be empty on entry
  * @returns #FALSE if no memory
  */
 dbus_bool_t
-_dbus_append_session_config_file (DBusString *str)
+_dbus_get_session_config_file (DBusString *str)
 {
+  _dbus_assert (_dbus_string_get_length (str) == 0);
+
   return _dbus_string_append (str, DBUS_SESSION_CONFIG_FILE);
 }
index 096ffee..d38f02b 100644 (file)
@@ -1469,73 +1469,68 @@ _dbus_command_for_pid (unsigned long  pid,
   return FALSE;
 }
 
-/*
- * replaces the term DBUS_PREFIX in configure_time_path by the
- * current dbus installation directory. On unix this function is a noop
+/**
+ * Replace the DBUS_PREFIX in the given path, in-place, by the
+ * current D-Bus installation directory. On Unix this function
+ * does nothing, successfully.
  *
- * @param configure_time_path
- * @return real path
+ * @param path path to edit
+ * @return #FALSE on OOM
  */
-const char *
-_dbus_replace_install_prefix (const char *configure_time_path)
+dbus_bool_t
+_dbus_replace_install_prefix (DBusString *path)
 {
 #ifndef DBUS_PREFIX
-  return configure_time_path;
+  /* leave path unchanged */
+  return TRUE;
 #else
-  static char retval[1000];
-  static char runtime_prefix[1000];
-  int len = 1000;
+  DBusString runtime_prefix;
   int i;
 
-  if (!configure_time_path)
-    return NULL;
-
-  if ((!_dbus_get_install_root(runtime_prefix, len) ||
-       strncmp (configure_time_path, DBUS_PREFIX "/",
-                strlen (DBUS_PREFIX) + 1))) {
-     strncpy (retval, configure_time_path, sizeof (retval) - 1);
-     /* strncpy does not guarantee to 0-terminate the string */
-     retval[sizeof (retval) - 1] = '\0';
-  } else {
-     size_t remaining;
-
-     strncpy (retval, runtime_prefix, sizeof (retval) - 1);
-     retval[sizeof (retval) - 1] = '\0';
-     remaining = sizeof (retval) - 1 - strlen (retval);
-     strncat (retval,
-         configure_time_path + strlen (DBUS_PREFIX) + 1,
-         remaining);
-  }
+  if (!_dbus_string_init (&runtime_prefix))
+    return FALSE;
+
+  if (!_dbus_get_install_root (&runtime_prefix))
+    {
+      _dbus_string_free (&runtime_prefix);
+      return FALSE;
+    }
+
+  if (_dbus_string_get_length (&runtime_prefix) == 0)
+    {
+      /* cannot determine install root, leave path unchanged */
+      _dbus_string_free (&runtime_prefix);
+      return TRUE;
+    }
+
+  if (_dbus_string_starts_with_c_str (path, DBUS_PREFIX "/"))
+    {
+      /* Replace DBUS_PREFIX "/" with runtime_prefix.
+       * Note unusual calling convention: source is first, then dest */
+      if (!_dbus_string_replace_len (
+            &runtime_prefix, 0, _dbus_string_get_length (&runtime_prefix),
+            path, 0, strlen (DBUS_PREFIX) + 1))
+        {
+          _dbus_string_free (&runtime_prefix);
+          return FALSE;
+        }
+    }
 
   /* Somehow, in some situations, backslashes get collapsed in the string.
    * Since windows C library accepts both forward and backslashes as
    * path separators, convert all backslashes to forward slashes.
    */
 
-  for(i = 0; retval[i] != '\0'; i++) {
-    if(retval[i] == '\\')
-      retval[i] = '/';
-  }
-  return retval;
-#endif
-}
-
-/**
- * return the relocated DATADIR
- *
- * @returns relocated DATADIR static string
- */
+  for (i = 0; i < _dbus_string_get_length (path); i++)
+    {
+      if (_dbus_string_get_byte (path, i) == '\\')
+        _dbus_string_set_byte (path, i, '/');
+    }
 
-static const char *
-_dbus_windows_get_datadir (void)
-{
-       return _dbus_replace_install_prefix(DBUS_DATADIR);
+  return TRUE;
+#endif
 }
 
-#undef DBUS_DATADIR
-#define DBUS_DATADIR _dbus_windows_get_datadir ()
-
-
 #define DBUS_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
 #define DBUS_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"
 
@@ -1579,27 +1574,30 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs)
       }
   }
 #else
-/*
- the code for accessing services requires absolute base pathes
- in case DBUS_DATADIR is relative make it absolute
-*/
-#ifdef DBUS_WIN
   {
     DBusString p;
 
-    _dbus_string_init_const (&p, DBUS_DATADIR);
+    if (!_dbus_string_init (&p))
+      goto oom;
 
-    if (!_dbus_path_is_absolute (&p))
+    /* DBUS_DATADIR is assumed to be absolute; the build systems should
+     * ensure that. */
+    if (!_dbus_string_append (&p, DBUS_DATADIR) ||
+        !_dbus_replace_install_prefix (&p))
       {
-        char install_root[1000];
-        if (_dbus_get_install_root (install_root, sizeof(install_root)))
-          if (!_dbus_string_append (&servicedir_path, install_root))
-            goto oom;
+        _dbus_string_free (&p);
+        goto oom;
+      }
+
+    if (!_dbus_string_append (&servicedir_path,
+          _dbus_string_get_const_data (&p)))
+      {
+        _dbus_string_free (&p);
+        goto oom;
       }
+
+    _dbus_string_free (&p);
   }
-#endif
-  if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR))
-    goto oom;
 
   if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
     goto oom;
@@ -1660,7 +1658,8 @@ _dbus_get_config_file_name (DBusString *str,
 {
   DBusString tmp;
 
-  if (!_dbus_string_append (str, _dbus_windows_get_datadir ()))
+  if (!_dbus_string_append (str, DBUS_DATADIR) ||
+      !_dbus_replace_install_prefix (str))
     return FALSE;
 
   _dbus_string_init_const (&tmp, "dbus-1");
@@ -1677,27 +1676,31 @@ _dbus_get_config_file_name (DBusString *str,
 }
 
 /**
- * Append the absolute path of the system.conf file
+ * Get the absolute path of the system.conf file
  * (there is no system bus on Windows so this can just
  * return FALSE and print a warning or something)
  *
- * @param str the string to append to
+ * @param str the string to append to, which must be empty on entry
  * @returns #FALSE if no memory
  */
 dbus_bool_t
-_dbus_append_system_config_file (DBusString *str)
+_dbus_get_system_config_file (DBusString *str)
 {
+  _dbus_assert (_dbus_string_get_length (str) == 0);
+
   return _dbus_get_config_file_name(str, "system.conf");
 }
 
 /**
- * Append the absolute path of the session.conf file.
+ * Get the absolute path of the session.conf file.
  *
- * @param str the string to append to
+ * @param str the string to append to, which must be empty on entry
  * @returns #FALSE if no memory
  */
 dbus_bool_t
-_dbus_append_session_config_file (DBusString *str)
+_dbus_get_session_config_file (DBusString *str)
 {
+  _dbus_assert (_dbus_string_get_length (str) == 0);
+
   return _dbus_get_config_file_name(str, "session.conf");
 }
index 69644b0..7ddb7fd 100644 (file)
@@ -2812,15 +2812,12 @@ _dbus_get_install_root_as_hash(DBusString *out)
 {
     DBusString install_path;
 
-    char path[MAX_PATH*2];
-    int path_size = sizeof(path);
+    _dbus_string_init(&install_path);
 
-    if (!_dbus_get_install_root(path,path_size))
+    if (!_dbus_get_install_root (&install_path) ||
+        _dbus_string_get_length (&install_path) == 0)
         return FALSE;
 
-    _dbus_string_init(&install_path);
-    _dbus_string_append(&install_path,path);
-
     _dbus_string_init(out);
     _dbus_string_tolower_ascii(&install_path,0,_dbus_string_get_length(&install_path));
 
@@ -3288,34 +3285,73 @@ _dbus_get_is_errno_eagain_or_ewouldblock (int e)
 }
 
 /**
- * return the absolute path of the dbus installation 
+ * Fill str with the absolute path of the D-Bus installation, or truncate str
+ * to zero length if we cannot determine it.
  *
- * @param prefix buffer for installation path
- * @param len length of buffer
- * @returns #FALSE on failure
+ * @param str buffer for installation path
+ * @returns #FALSE on OOM, #TRUE if not OOM
  */
 dbus_bool_t
-_dbus_get_install_root(char *prefix, int len)
+_dbus_get_install_root (DBusString *str)
 {
-    //To find the prefix, we cut the filename and also \bin\ if present
-    DWORD pathLength;
+    /* this is just an initial guess */
+    DWORD pathLength = MAX_PATH;
     char *lastSlash;
-    SetLastError( 0 );
-    pathLength = GetModuleFileNameA(_dbus_win_get_dll_hmodule(), prefix, len);
-    if ( pathLength == 0 || GetLastError() != 0 ) {
-        *prefix = '\0';
-        return FALSE;
-    }
+    char *prefix;
+
+    do
+      {
+        /* allocate enough space for our best guess at the length */
+        if (!_dbus_string_set_length (str, pathLength))
+          {
+            _dbus_string_set_length (str, 0);
+            return FALSE;
+          }
+
+        SetLastError (0);
+        pathLength = GetModuleFileNameA (_dbus_win_get_dll_hmodule (),
+            _dbus_string_get_data (str), _dbus_string_get_length (str));
+
+        if (pathLength == 0 || GetLastError () != 0)
+          {
+            /* failed, but not OOM */
+            _dbus_string_set_length (str, 0);
+            return TRUE;
+          }
+
+        /* if the return is strictly less than the buffer size, it has
+         * not been truncated, so we can continue */
+        if (pathLength < (DWORD) _dbus_string_get_length (str))
+          {
+            /* reduce the length to match what Windows filled in */
+            if (!_dbus_string_set_length (str, pathLength))
+              {
+                _dbus_string_set_length (str, 0);
+                return FALSE;
+              }
+
+            break;
+          }
+
+        /* else it may have been truncated; try with a larger buffer */
+        pathLength *= 2;
+      }
+    while (TRUE);
+
+    /* the rest of this function works by direct byte manipulation of the
+     * underlying buffer */
+    prefix = _dbus_string_get_data (str);
+
     lastSlash = _mbsrchr(prefix, '\\');
     if (lastSlash == NULL) {
-        *prefix = '\0';
-        return FALSE;
+        /* failed, but not OOM */
+        _dbus_string_set_length (str, 0);
+        return TRUE;
     }
     //cut off binary name
     lastSlash[1] = 0;
 
     //cut possible "\\bin"
-
     //this fails if we are in a double-byte system codepage and the
     //folder's name happens to end with the *bytes*
     //"\\bin"... (I.e. the second byte of some Han character and then
@@ -3327,6 +3363,9 @@ _dbus_get_install_root(char *prefix, int len)
     else if (lastSlash - prefix >= 12 && strnicmp(lastSlash - 12, "\\bin\\release", 12) == 0)
         lastSlash[-11] = 0;
 
+    /* fix up the length to match the byte-manipulation */
+    _dbus_string_set_length (str, strlen (prefix));
+
     return TRUE;
 }
 
index e9b30d7..0b5d8f0 100644 (file)
@@ -85,7 +85,7 @@ _dbus_win_sid_to_name_and_domain (dbus_uid_t uid,
 dbus_bool_t _dbus_file_exists (const char *filename);
 
 DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_get_install_root(char *prefix, int len);
+dbus_bool_t _dbus_get_install_root (DBusString *str);
 
 void        _dbus_threads_windows_init_global (void);
 void        _dbus_threads_windows_ensure_ctor_linked (void);
index 79a6cc7..bd0356e 100644 (file)
@@ -432,8 +432,8 @@ dbus_bool_t _dbus_path_is_absolute    (const DBusString *filename);
 dbus_bool_t _dbus_get_standard_session_servicedirs (DBusList **dirs);
 dbus_bool_t _dbus_get_standard_system_servicedirs (DBusList **dirs);
 
-dbus_bool_t _dbus_append_system_config_file  (DBusString *str);
-dbus_bool_t _dbus_append_session_config_file (DBusString *str);
+dbus_bool_t _dbus_get_system_config_file  (DBusString *str);
+dbus_bool_t _dbus_get_session_config_file (DBusString *str);
 
 /** Opaque type for reading a directory listing */
 typedef struct DBusDirIter DBusDirIter;
@@ -647,15 +647,7 @@ dbus_bool_t _dbus_change_to_daemon_user (const char *user,
 DBUS_PRIVATE_EXPORT
 void _dbus_flush_caches (void);
 
-/*
- * replaces the term DBUS_PREFIX in configure_time_path by the
- * current dbus installation directory. On unix this function is a noop
- *
- * @param configure_time_path
- * @return real path
- */
-const char *
-_dbus_replace_install_prefix (const char *configure_time_path);
+dbus_bool_t _dbus_replace_install_prefix (DBusString *path);
 
 /* Do not set this too high: it is a denial-of-service risk.
  * See <https://bugs.freedesktop.org/show_bug.cgi?id=82820>
index e392c5c..c86ed6b 100644 (file)
 
 static dbus_bool_t print_install_root()
 {
-  char runtime_prefix[1000];
+  DBusString runtime_prefix;
 
-  if (!_dbus_get_install_root(runtime_prefix, sizeof(runtime_prefix)))
+  if (!_dbus_string_init (&runtime_prefix))
     {
-      fprintf(stderr, "dbus_get_install_root() failed\n");
+      _dbus_assert_not_reached ("out of memory");
       return FALSE;
     }
-  fprintf(stdout, "dbus_get_install_root() returned '%s'\n", runtime_prefix);
+
+  if (!_dbus_get_install_root (&runtime_prefix))
+    {
+      _dbus_assert_not_reached ("out of memory");
+      _dbus_string_free (&runtime_prefix);
+      return FALSE;
+    }
+
+  if (_dbus_string_get_length (&runtime_prefix) == 0)
+    {
+      fprintf (stderr, "_dbus_get_install_root() failed\n");
+      _dbus_string_free (&runtime_prefix);
+      return FALSE;
+    }
+
+  fprintf (stdout, "_dbus_get_install_root() returned '%s'\n",
+      _dbus_string_get_const_data (&runtime_prefix));
+  _dbus_string_free (&runtime_prefix);
   return TRUE;
 }
 
@@ -46,11 +63,25 @@ static dbus_bool_t print_service_dirs()
 
 static dbus_bool_t print_replace_install_prefix(const char *s)
 {
-  const char *s2 = _dbus_replace_install_prefix(s);
-  if (!s2)
-    return FALSE;
+  DBusString str;
+
+  if (!_dbus_string_init (&str))
+    {
+      _dbus_assert_not_reached ("out of memory");
+      return FALSE;
+    }
+
+  if (!_dbus_string_append (&str, s) ||
+      !_dbus_replace_install_prefix (&str))
+    {
+      _dbus_assert_not_reached ("out of memory");
+      _dbus_string_free (&str);
+      return FALSE;
+    }
 
-  fprintf(stdout, "replaced '%s' by '%s'\n", s, s2);
+  fprintf(stdout, "replaced '%s' by '%s'\n", s,
+      _dbus_string_get_const_data (&str));
+  _dbus_string_free (&str);
   return TRUE;
 }
 
index 80c9698..b747e87 100644 (file)
 
 #include "tool-common.h"
 
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+
+#if defined(DBUS_WIN)
+#if !defined(PRId64)
+#define PRId64 "I64d"
+#endif
+#if !defined(PRIu64)
+#define PRIu64 "I64u"
+#endif
+#endif
+
 static const char*
 type_to_name (int message_type)
 {
@@ -384,11 +397,7 @@ print_iter (DBusMessageIter *iter, dbus_bool_t literal, int depth)
           {
             dbus_int64_t val;
             dbus_message_iter_get_basic (iter, &val);
-#ifdef DBUS_INT64_PRINTF_MODIFIER
-        printf ("int64 %" DBUS_INT64_PRINTF_MODIFIER "d\n", val);
-#else
-        printf ("int64 (omitted)\n");
-#endif
+            printf ("int64 %" PRId64 "\n", val);
             break;
           }
 
@@ -396,11 +405,7 @@ print_iter (DBusMessageIter *iter, dbus_bool_t literal, int depth)
           {
             dbus_uint64_t val;
             dbus_message_iter_get_basic (iter, &val);
-#ifdef DBUS_INT64_PRINTF_MODIFIER
-        printf ("uint64 %" DBUS_INT64_PRINTF_MODIFIER "u\n", val);
-#else
-        printf ("uint64 (omitted)\n");
-#endif
+            printf ("uint64 %" PRIu64 "\n", val);
             break;
           }