From f4971b225e716ebc7278042d469136328c68f520 Mon Sep 17 00:00:00 2001 From: John (J5) Palmieri Date: Tue, 20 Nov 2007 16:00:02 -0500 Subject: [PATCH] fix off by one error message (#13305) 2007-11-20 John (J5) Palmieri * dbus/dbus-message.c (_dbus_message_iter_get_args_valist): use a different counter when iterating arrays. When constructing the error string add one to the counter to get the true argument count --- ChangeLog | 6 ++++++ dbus/dbus-message.c | 16 ++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0dc40d8..f59e83f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-11-20 John (J5) Palmieri + + * dbus/dbus-message.c (_dbus_message_iter_get_args_valist): use a + different counter when iterating arrays. When constructing the error + string add one to the counter to get the true argument count + 2007-10-31 Havoc Pennington * bus/selinux.c (log_audit_callback): rewrite to use diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index cd44798..22174bb 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -644,7 +644,7 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter, va_list var_args) { DBusMessageRealIter *real = (DBusMessageRealIter *)iter; - int spec_type, msg_type, i; + int spec_type, msg_type, i, j; dbus_bool_t retval; _dbus_assert (_dbus_message_iter_check (real)); @@ -750,7 +750,7 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter, /* Now go through and dup each string */ _dbus_type_reader_recurse (&real->u.reader, &array); - i = 0; + j = 0; while (i < n_elements) { const char *s; @@ -758,22 +758,22 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter, &s); str_array[i] = _dbus_strdup (s); - if (str_array[i] == NULL) + if (str_array[j] == NULL) { dbus_free_string_array (str_array); _DBUS_SET_OOM (error); goto out; } - ++i; + ++j; if (!_dbus_type_reader_next (&array)) - _dbus_assert (i == n_elements); + _dbus_assert (j == n_elements); } _dbus_assert (_dbus_type_reader_get_current_type (&array) == DBUS_TYPE_INVALID); - _dbus_assert (i == n_elements); - _dbus_assert (str_array[i] == NULL); + _dbus_assert (j == n_elements); + _dbus_assert (str_array[j] == NULL); *str_array_p = str_array; *n_elements_p = n_elements; @@ -800,7 +800,7 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter, if (!_dbus_type_reader_next (&real->u.reader) && spec_type != DBUS_TYPE_INVALID) { dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, - "Message has only %d arguments, but more were expected", i); + "Message has only %d arguments, but more were expected", i + 1); goto out; } -- 1.5.3.4