]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Cleanup zero string length case condition in Windows helper functions
authorRalf Habacker <ralf.habacker@freenet.de>
Wed, 15 Dec 2021 08:31:15 +0000 (09:31 +0100)
committerRalf Habacker <ralf.habacker@freenet.de>
Thu, 16 Dec 2021 09:04:47 +0000 (10:04 +0100)
This cleanup has been processed in _dbus_daemon_publish_session_bus_address()
_dbus_get_install_root_as_hash() and _dbus_get_address_string().

The zero length condition has been catched in each function calling
the mentioned functions.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
dbus/dbus-sysdeps-win.c

index deb275a83f140b45cbadb4d37cc528f934fc96ba..cfa846ebbfe215682836e25ed42e9528b6582504 100644 (file)
@@ -2938,6 +2938,9 @@ static const char *cDBusDaemonAddressInfo = "DBusDaemonAddressInfo";
  * Return the hash of the installation root directory, which can be
  * used to construct a per-installation-root scope for autolaunching
  *
+ * If the installation root directory could not be
+ * determined, the returned length is set to zero.
+ *
  * @param out initialized DBusString instance to return hash string
  * @returns #FALSE on OOM, #TRUE if not OOM
  */
@@ -2951,10 +2954,17 @@ _dbus_get_install_root_as_hash (DBusString *out)
   if (!_dbus_string_init (&install_path))
     return FALSE;
 
-  if (!_dbus_get_install_root (&install_path) ||
-      _dbus_string_get_length (&install_path) == 0)
+  if (!_dbus_get_install_root (&install_path))
     goto out;
 
+  /* the install path can't be determined */
+  if (_dbus_string_get_length (&install_path) == 0)
+    {
+      _dbus_string_set_length (out, 0);
+      retval = TRUE;
+      goto out;
+    }
+
   _dbus_string_tolower_ascii (&install_path, 0, _dbus_string_get_length (&install_path));
 
   if (!_dbus_sha_compute (&install_path, out))
@@ -2979,6 +2989,9 @@ out:
  * (the username or the hash of the installation path) instead of the
  * literal scope itself.
  *
+ * With the '*install-path' \p scope the returned length can be zero,
+ * indicating that the name could not be determined.
+ *
  * @param out initialized DBusString instance to return bus address
  * @returns #FALSE on OOM, #TRUE if not OOM
  */
@@ -3078,7 +3091,9 @@ _dbus_daemon_is_session_bus_address_published (const char *scope)
     return FALSE;
 
   _dbus_verbose ("scope:%s\n", scope);
-  if (!_dbus_get_mutex_name (&mutex_name, scope))
+  if (!_dbus_get_mutex_name (&mutex_name, scope) ||
+      /* not determinable */
+      _dbus_string_get_length (&mutex_name) == 0)
     {
       _dbus_string_free (&mutex_name);
       return FALSE;
@@ -3139,7 +3154,9 @@ _dbus_daemon_publish_session_bus_address (const char* address, const char *scope
     return FALSE;
 
   _dbus_verbose ("address:%s scope:%s\n", address, scope);
-  if (!_dbus_get_mutex_name (&mutex_name, scope))
+  if (!_dbus_get_mutex_name (&mutex_name, scope) ||
+      /* not determinable */
+      _dbus_string_get_length (&mutex_name) == 0)
     {
       _dbus_string_free (&mutex_name);
       return FALSE;
@@ -3168,7 +3185,9 @@ _dbus_daemon_publish_session_bus_address (const char* address, const char *scope
       return FALSE;
     }
 
-  if (!_dbus_get_shm_name (&shm_name, scope))
+  if (!_dbus_get_shm_name (&shm_name, scope) ||
+      /* not determinable */
+      _dbus_string_get_length (&shm_name) == 0)
     {
       _dbus_string_free (&shm_name);
       _dbus_global_unlock (lock);
@@ -3285,7 +3304,9 @@ _dbus_daemon_already_runs (DBusString *address, DBusString *shm_name, const char
   if (!_dbus_string_init (&mutex_name))
     return FALSE;
 
-  if (!_dbus_get_mutex_name (&mutex_name,scope))
+  if (!_dbus_get_mutex_name (&mutex_name,scope) ||
+      /* not determinable */
+      _dbus_string_get_length (&mutex_name) == 0)
     {
       _dbus_string_free (&mutex_name);
       return FALSE;
@@ -3341,7 +3362,9 @@ _dbus_get_autolaunch_address (const char *scope,
       return FALSE;
     }
 
-  if (!_dbus_get_shm_name (&shm_name, scope))
+  if (!_dbus_get_shm_name (&shm_name, scope) ||
+      /* not determinable */
+      _dbus_string_get_length (&shm_name) == 0)
     {
       dbus_set_error_const (error, DBUS_ERROR_FAILED, "could not determine shm name");
       goto out;