summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Andrieu <oliv__a@users.sourceforge.net>2004-03-21 13:42:23 +0000
committerOlivier Andrieu <oliv__a@users.sourceforge.net>2004-03-21 13:42:23 +0000
commiteacb2afdc2903874f5dfde80b4ee338ea333c75e (patch)
tree1324bd2b577fcd281231f32762030d6e3b6657df
parent4fd4d52dd679486edc4543cd93c9f4d01cd8f90e (diff)
downloaddbus-eacb2afdc2903874f5dfde80b4ee338ea333c75e.tar.gz
* 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
-rw-r--r--ChangeLog13
-rw-r--r--dbus/dbus-marshal.c16
-rw-r--r--dbus/dbus-message.c64
-rw-r--r--dbus/dbus-message.h6
-rw-r--r--dbus/dbus-pending-call.c2
-rw-r--r--dbus/dbus-server.c2
6 files changed, 86 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 8685abeb..536ec98f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2004-03-21 Olivier Andrieu <oliv__a@users.sourceforge.net>
+
+ * 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
+
2004-03-19 Havoc Pennington <hp@redhat.com>
* NEWS: 0.21 updates
diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c
index e19e36bb..7524452b 100644
--- a/dbus/dbus-marshal.c
+++ b/dbus/dbus-marshal.c
@@ -2116,7 +2116,10 @@ _dbus_marshal_validate_arg (const DBusString *str,
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 @@ _dbus_marshal_validate_arg (const DBusString *str,
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)
{
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 63e2afe7..6ae5a933 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -2361,15 +2361,16 @@ dbus_message_iter_get_args_valist (DBusMessageIter *iter,
*
* @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 @@ dbus_message_iter_init (DBusMessage *message,
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 @@ dbus_message_iter_get_double (DBusMessageIter *iter)
* @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 @@ dbus_message_iter_init_array_iterator (DBusMessageIter *iter,
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 @@ dbus_message_iter_init_array_iterator (DBusMessageIter *iter,
if (array_type != NULL)
*array_type = _array_type;
+
+ return len > 0;
}
@@ -2995,8 +3001,9 @@ dbus_message_iter_init_array_iterator (DBusMessageIter *iter,
*
* @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 @@ dbus_message_iter_init_dict_iterator (DBusMessageIter *iter,
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 @@ dbus_message_iter_init_dict_iterator (DBusMessageIter *iter,
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 @@ message_iter_test (DBusMessage *message)
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_test (const char *test_data_dir)
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 */
diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h
index d9ddc94c..02fa181b 100644
--- a/dbus/dbus-message.h
+++ b/dbus/dbus-message.h
@@ -150,7 +150,7 @@ dbus_bool_t dbus_message_iter_get_args_valist (DBusMessageIter *iter,
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 @@ dbus_bool_t dbus_message_iter_get_custom (DBusMessageIter *iter
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,
diff --git a/dbus/dbus-pending-call.c b/dbus/dbus-pending-call.c
index e7173490..5ea62c59 100644
--- a/dbus/dbus-pending-call.c
+++ b/dbus/dbus-pending-call.c
@@ -143,7 +143,7 @@ _dbus_pending_call_notify (DBusPendingCall *pending)
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);
diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c
index b97b1ca7..339f8360 100644
--- a/dbus/dbus-server.c
+++ b/dbus/dbus-server.c
@@ -455,7 +455,7 @@ dbus_server_listen (const char *address,
DBusServer *
dbus_server_ref (DBusServer *server)
{
- _dbus_return_if_fail (server != NULL);
+ _dbus_return_val_if_fail (server != NULL, NULL);
server->refcount += 1;