dbus/dbus dbus-server.c, 1.32, 1.33 dbus-pending-call.c, 1.6, 1.7 dbus-message.h, 1.50, 1.51 dbus-message.c, 1.122, 1.123 dbus-marshal.c, 1.48, 1.49

Olivier Andrieu oandrieu at pdx.freedesktop.org
Sun Mar 21 05:42:25 PST 2004


Update of /cvs/dbus/dbus/dbus
In directory pdx:/tmp/cvs-serv24246/dbus

Modified Files:
	dbus-server.c dbus-pending-call.c dbus-message.h 
	dbus-message.c dbus-marshal.c 
Log Message:
* dbus/dbus-marshal.c (_dbus_marshal_validate_arg): accept empty
arrays

* dbus/dbus-message.h, bus/dbus-message.c (dbus_message_iter_init)
(dbus_message_iter_init_array_iterator)
(dbus_message_iter_init_dict_iterator): return a dbus_bool_t to
indicate whether the iterator is empty

* dbus/dbus-pending-call.c, dbus/dbus-server.c: silence compiler
warnings


Index: dbus-server.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- a/dbus-server.c	2 Dec 2003 10:44:21 -0000	1.32
+++ b/dbus-server.c	21 Mar 2004 13:42:23 -0000	1.33
@@ -455,7 +455,7 @@
 DBusServer *
 dbus_server_ref (DBusServer *server)
 {
-  _dbus_return_if_fail (server != NULL);
+  _dbus_return_val_if_fail (server != NULL, NULL);
   
   server->refcount += 1;
 

Index: dbus-pending-call.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-pending-call.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- a/dbus-pending-call.c	2 Dec 2003 10:44:21 -0000	1.6
+++ b/dbus-pending-call.c	21 Mar 2004 13:42:23 -0000	1.7
@@ -143,7 +143,7 @@
 DBusPendingCall *
 dbus_pending_call_ref (DBusPendingCall *pending)
 {
-  _dbus_return_if_fail (pending != NULL);
+  _dbus_return_val_if_fail (pending != NULL, NULL);
 
   _dbus_atomic_inc (&pending->refcount);
 

Index: dbus-message.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.h,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- a/dbus-message.h	16 Mar 2004 18:00:35 -0000	1.50
+++ b/dbus-message.h	21 Mar 2004 13:42:23 -0000	1.51
@@ -150,7 +150,7 @@
 					       va_list          var_args);
 
 
-void                   dbus_message_iter_init            (DBusMessage      *message,
+dbus_bool_t            dbus_message_iter_init            (DBusMessage      *message,
                                                           DBusMessageIter  *iter);
 dbus_bool_t            dbus_message_iter_has_next        (DBusMessageIter  *iter);
 dbus_bool_t            dbus_message_iter_next            (DBusMessageIter  *iter);
@@ -173,10 +173,10 @@
                                                           unsigned char   **value,
                                                           int              *len);
 
-void        dbus_message_iter_init_array_iterator (DBusMessageIter   *iter,
+dbus_bool_t dbus_message_iter_init_array_iterator (DBusMessageIter   *iter,
 						   DBusMessageIter   *array_iter,
 						   int               *array_type);
-void        dbus_message_iter_init_dict_iterator  (DBusMessageIter   *iter,
+dbus_bool_t dbus_message_iter_init_dict_iterator  (DBusMessageIter   *iter,
 						   DBusMessageIter   *dict_iter);
 dbus_bool_t dbus_message_iter_get_byte_array      (DBusMessageIter   *iter,
 						   unsigned char    **value,

Index: dbus-message.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.c,v
retrieving revision 1.122
retrieving revision 1.123
diff -u -d -r1.122 -r1.123
--- a/dbus-message.c	18 Mar 2004 11:10:59 -0000	1.122
+++ b/dbus-message.c	21 Mar 2004 13:42:23 -0000	1.123
@@ -2361,15 +2361,16 @@
  *
  * @param message the message
  * @param iter pointer to an iterator to initialize
+ * @returns #FALSE if the message has no arguments
  */
-void
+dbus_bool_t
 dbus_message_iter_init (DBusMessage     *message,
 			DBusMessageIter *iter)
 {
   DBusMessageRealIter *real = (DBusMessageRealIter *)iter;
 
-  _dbus_return_if_fail (message != NULL);
-  _dbus_return_if_fail (iter != NULL);
+  _dbus_return_val_if_fail (message != NULL, FALSE);
+  _dbus_return_val_if_fail (iter != NULL, FALSE);
   
   _dbus_assert (sizeof (DBusMessageRealIter) <= sizeof (DBusMessageIter));
   
@@ -2385,6 +2386,8 @@
   real->container_length_pos = 0;
   real->wrote_dict_key = 0;
   real->array_type_pos = 0;
+
+  return real->end > real->pos;
 }
 
 #ifndef DBUS_DISABLE_CHECKS
@@ -2946,8 +2949,9 @@
  * @param iter the iterator
  * @param array_iter pointer to an iterator to initialize
  * @param array_type gets set to the type of the array elements
+ * @returns #FALSE if the array is empty
  */
-void
+dbus_bool_t
 dbus_message_iter_init_array_iterator (DBusMessageIter *iter,
 				       DBusMessageIter *array_iter,
 				       int             *array_type)
@@ -2957,7 +2961,7 @@
   int type, pos, len_pos, len, array_type_pos;
   int _array_type;
 
-  _dbus_return_if_fail (dbus_message_iter_check (real));
+  _dbus_return_val_if_fail (dbus_message_iter_check (real), FALSE);
 
   pos = dbus_message_iter_get_data_start (real, &type);
   
@@ -2985,6 +2989,8 @@
   
   if (array_type != NULL)
     *array_type = _array_type;
+
+  return len > 0;
 }
 
 
@@ -2995,8 +3001,9 @@
  *
  * @param iter the iterator
  * @param dict_iter pointer to an iterator to initialize
+ * @returns #FALSE if the dict is empty
  */
-void
+dbus_bool_t
 dbus_message_iter_init_dict_iterator (DBusMessageIter *iter,
 				      DBusMessageIter *dict_iter)
 {
@@ -3004,7 +3011,7 @@
   DBusMessageRealIter *dict_real = (DBusMessageRealIter *)dict_iter;
   int type, pos, len_pos, len;
 
-  _dbus_return_if_fail (dbus_message_iter_check (real));
+  _dbus_return_val_if_fail (dbus_message_iter_check (real), FALSE);
 
   pos = dbus_message_iter_get_data_start (real, &type);
   
@@ -3025,6 +3032,8 @@
   dict_real->container_start = pos;
   dict_real->container_length_pos = len_pos;
   dict_real->wrote_dict_key = 0;
+
+  return len > 0;
 }
 
 /**
@@ -6055,6 +6064,39 @@
   if (dbus_message_iter_get_byte (&iter) != 0xF0)
     _dbus_assert_not_reached ("wrong value after custom");
 
+  if (!dbus_message_iter_next (&iter))
+    _dbus_assert_not_reached ("Reached end of arguments");
+
+  if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY)
+    _dbus_assert_not_reached ("no array");
+
+  if (dbus_message_iter_get_array_type (&iter) != DBUS_TYPE_INT32)
+    _dbus_assert_not_reached ("Array type not int32");
+
+  if (dbus_message_iter_init_array_iterator (&iter, &array, NULL))
+    _dbus_assert_not_reached ("non empty array");
+  
+  if (!dbus_message_iter_next (&iter))
+    _dbus_assert_not_reached ("Reached end of arguments");
+
+  if (dbus_message_iter_get_byte (&iter) != 0xF0)
+    _dbus_assert_not_reached ("wrong value after empty array");
+
+  if (!dbus_message_iter_next (&iter))
+    _dbus_assert_not_reached ("Reached end of arguments");
+
+  if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_DICT)
+    _dbus_assert_not_reached ("non dict");
+
+  if (dbus_message_iter_init_dict_iterator (&iter, &dict))
+    _dbus_assert_not_reached ("non empty dict");
+
+  if (!dbus_message_iter_next (&iter))
+    _dbus_assert_not_reached ("Reached end of arguments");
+
+  if (dbus_message_iter_get_byte (&iter) != 0xF0)
+    _dbus_assert_not_reached ("wrong value after empty dict");
+
   if (dbus_message_iter_next (&iter))
     _dbus_assert_not_reached ("Didn't reach end of arguments");
 }
@@ -7194,6 +7236,14 @@
   
   dbus_message_iter_append_byte (&iter, 0xF0);
 
+  dbus_message_iter_append_array (&iter, &child_iter, DBUS_TYPE_INT32);
+
+  dbus_message_iter_append_byte (&iter, 0xF0);
+
+  dbus_message_iter_append_dict (&iter, &child_iter);
+
+  dbus_message_iter_append_byte (&iter, 0xF0);
+
   message_iter_test (message);
   
   /* Message loader test */

Index: dbus-marshal.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- a/dbus-marshal.c	12 Mar 2004 14:18:35 -0000	1.48
+++ b/dbus-marshal.c	21 Mar 2004 13:42:23 -0000	1.49
@@ -2116,7 +2116,10 @@
         
 	len = demarshal_and_validate_len (str, byte_order, pos, &pos);
         if (len < 0)
-          return FALSE;
+	  {
+	    _dbus_verbose ("invalid array length (<0)\n");
+	    return FALSE;
+	  }
 
         if (len > _dbus_string_get_length (str) - pos)
           {
@@ -2126,10 +2129,13 @@
 	
 	end = pos + len;
 
-        if (!validate_array_data (str, byte_order, depth + 1,
-                                  array_type, array_type_pos,
-                                  pos, &pos, end))
-          return FALSE;
+        if (len > 0 && !validate_array_data (str, byte_order, depth + 1,
+					     array_type, array_type_pos,
+					     pos, &pos, end))
+	  {
+	    _dbus_verbose ("invalid array data\n");
+	    return FALSE;
+	  }
 
         if (pos < end)
           {




More information about the dbus-commit mailing list