Unix transport bug (and a possible fix)

Anders Carlsson andersca@codefactory.se
20 Jun 2003 15:58:02 +0200


--=-7Fjq77AtJqolB9Hauoqt
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hello,

currently, if a client sends a message and disconnects within a very
short period of time then the message may be discarded by the server.

This is because both DBUS_WATCH_READABLE and DBUS_WATCH_HANGUP are set
in the same call to unix_handle_watch. This function checks for hangup
before checking for readable, and thus closes the socket and returns
before reading the data.

The attached patch fixes it by checking for error and hangup last.

Is it ok to commit?

Anders

--=-7Fjq77AtJqolB9Hauoqt
Content-Disposition: attachment; filename=dbus-transport-fix.diff
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=dbus-transport-fix.diff; charset=UTF-8

Index: ChangeLog
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/ChangeLog,v
retrieving revision 1.371
diff -u -p -r1.371 ChangeLog
--- ChangeLog	19 Jun 2003 22:22:37 -0000	1.371
+++ ChangeLog	20 Jun 2003 13:43:35 -0000
@@ -1,3 +1,9 @@
+2003-06-20  Anders Carlsson  <andersca@codefactory.se>
+
+	* dbus/dbus-transport-unix.c (unix_handle_watch): Check=20
+	for hangup and error after checking read so we won't discard
+	pending data if both hangup and read are set.
+
 2003-06-19  Philip Blundell  <philb@gnu.org>
=20
 	* tools/dbus-print-message.c (print_message): Handle BOOLEAN.
Index: dbus/dbus-transport-unix.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/dbus/dbus-transport-unix.c,v
retrieving revision 1.32
diff -u -p -r1.32 dbus-transport-unix.c
--- dbus/dbus-transport-unix.c	4 Jun 2003 05:20:20 -0000	1.32
+++ dbus/dbus-transport-unix.c	20 Jun 2003 13:43:35 -0000
@@ -727,12 +727,6 @@ unix_handle_watch (DBusTransport *transp
   _dbus_assert (watch =3D=3D unix_transport->read_watch ||
                 watch =3D=3D unix_transport->write_watch);
  =20
-  if (flags & (DBUS_WATCH_HANGUP | DBUS_WATCH_ERROR))
-    {
-      _dbus_transport_disconnect (transport);
-      return TRUE;
-    }
- =20
   if (watch =3D=3D unix_transport->read_watch &&
       (flags & DBUS_WATCH_READABLE))
     {
@@ -779,6 +773,12 @@ unix_handle_watch (DBusTransport *transp
     }
 #endif /* DBUS_ENABLE_VERBOSE_MODE */
=20
+  if (flags & (DBUS_WATCH_HANGUP | DBUS_WATCH_ERROR))
+    {
+      _dbus_transport_disconnect (transport);
+      return TRUE;
+    }
+ =20
   return TRUE;
 }
=20

--=-7Fjq77AtJqolB9Hauoqt--