[patch] crash when connecting via tcp without specifying the host

Sjoerd Simons sjoerd at luon.net
Sat May 27 02:47:29 PDT 2006


Hi,

  When using the tcp transport without a host option 
  _dbus_transport_new_for_tcp_socket tries to append a NULL string to the
  address string. I've fixed that in the attached patch [0]. Note that i've
  split up the big if statement, with the host special case it just became to
  complex imho. 

  When testing this patch the connection refused error was:
    Failed to open connection to session message bus: Failed to connect to
    socket localhost: Connection refused:12346
  
  Which is quite strange. I would expect the port number after the hostname,
  not after the error message. So i also did a patch[1] to swap them, making it
  look like:
    Failed to open connection to session message bus: Failed to connect to
    socket localhost:1234 Connection refused
  
  Which is a lot more natural :)
  
  Please review. 

    Sjoerd
0: dbus-tcp-nohost.patch
1: dbus-tcp-conreff.patch
-- 
The Force is what holds everything together.  It has its dark side, and
it has its light side.  It's sort of like cosmic duct tape.
-------------- next part --------------
Index: dbus/dbus-transport-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport-unix.c,v
retrieving revision 1.48
diff -u -r1.48 dbus-transport-unix.c
--- dbus/dbus-transport-unix.c	25 Oct 2005 15:57:13 -0000	1.48
+++ dbus/dbus-transport-unix.c	27 May 2006 09:33:53 -0000
@@ -1272,16 +1272,18 @@
       return NULL;
     }
   
-  if (!_dbus_string_append (&address, "tcp:host=") ||
-      !_dbus_string_append (&address, host) ||
-      !_dbus_string_append (&address, ",port=") ||
+  if (!_dbus_string_append (&address, "tcp:"))
+    goto error;
+
+  if (host != NULL && 
+       (!_dbus_string_append (&address, "host=") ||
+        !_dbus_string_append (&address, host)))
+    goto error;
+
+  if (!_dbus_string_append (&address, ",port=") ||
       !_dbus_string_append_int (&address, port))
-    {
-      _dbus_string_free (&address);
-      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-      return NULL;
-    }
-  
+    goto error;
+
   fd = _dbus_connect_tcp_socket (host, port, error);
   if (fd < 0)
     {
@@ -1307,6 +1309,11 @@
   _dbus_string_free (&address);
   
   return transport;
+
+error:
+  _dbus_string_free (&address);
+  dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+  return NULL;
 }
 
 /** @} */
-------------- next part --------------
Index: dbus/dbus-sysdeps.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.c,v
retrieving revision 1.101
diff -u -r1.101 dbus-sysdeps.c
--- dbus/dbus-sysdeps.c	24 Feb 2006 16:13:08 -0000	1.101
+++ dbus/dbus-sysdeps.c	27 May 2006 09:33:27 -0000
@@ -678,8 +678,8 @@
     {      
       dbus_set_error (error,
                        _dbus_error_from_errno (errno),
-                      "Failed to connect to socket %s: %s:%d",
-                      host, _dbus_strerror (errno), port);
+                      "Failed to connect to socket %s:%d %s",
+                      host, port, _dbus_strerror (errno));
 
       close (fd);
       fd = -1;


More information about the dbus mailing list