From 0366385618ccc26789fdf3a9cc35ee038de071f6 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Tue, 8 Apr 2003 22:07:09 +0000 Subject: 2003-04-08 Havoc Pennington * test/data/invalid-messages/array-with-mixed-types.message: regression test that fails for the moment * dbus/dbus-test.c (dbus_internal_do_not_use_run_tests): reorder tests for convenience * dbus/dbus-marshal.c (_dbus_marshal_validate_arg): don't allow array of nil, it broke things. * test/data/invalid-messages/array-of-nil.message: regression test * test/data/valid-messages/array-of-array-of-uint32.message: happened to write this so added it to suite --- dbus/dbus-marshal.c | 36 +++++++++++++++++++++++++++++------- dbus/dbus-test.c | 52 ++++++++++++++++++++++++++-------------------------- 2 files changed, 55 insertions(+), 33 deletions(-) (limited to 'dbus') diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index 83a3e6f2..b1eb6fc7 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -1,7 +1,8 @@ /* -*- mode: C; c-file-style: "gnu" -*- */ /* dbus-marshal.c Marshalling routines * - * Copyright (C) 2002 CodeFactory AB + * Copyright (C) 2002 CodeFactory AB + * Copyright (C) 2003 Red Hat, Inc. * * Licensed under the Academic Free License version 1.2 * @@ -1344,7 +1345,17 @@ _dbus_marshal_validate_arg (const DBusString *str, _dbus_verbose ("invalid array type\n"); return FALSE; } - + + /* NIL values take up no space, so you couldn't iterate over an array of them. + * array of nil seems useless anyway; the useful thing might be array of + * (nil OR string) but we have no framework for that. + */ + if (array_type == DBUS_TYPE_NIL) + { + _dbus_verbose ("array of NIL is not allowed\n"); + return FALSE; + } + len = demarshal_and_validate_len (str, byte_order, pos, &pos); if (len < 0) return FALSE; @@ -1356,17 +1367,27 @@ _dbus_marshal_validate_arg (const DBusString *str, } end = pos + len; - + while (pos < end) { if (!_dbus_marshal_validate_arg (str, byte_order, depth + 1, array_type, pos, &pos)) return FALSE; } - + + if (pos < end) + { + /* This should not be able to happen, as long as validate_arg moves forward; + * but the check is here just to be paranoid. + */ + _dbus_verbose ("array length %d specified was longer than actual array contents by %d\n", + len, end - pos); + return FALSE; + } + if (pos > end) { - _dbus_verbose ("array contents exceeds array length\n"); + _dbus_verbose ("array contents exceeds array length %d by %d\n", len, pos - end); return FALSE; } @@ -1374,7 +1395,7 @@ _dbus_marshal_validate_arg (const DBusString *str, } break; - case DBUS_TYPE_DICT: + case DBUS_TYPE_DICT: { int dict_type; int len; @@ -1413,9 +1434,10 @@ _dbus_marshal_validate_arg (const DBusString *str, if (pos > end) { - _dbus_verbose ("dict contents exceeds array length\n"); + _dbus_verbose ("dict contents exceed stated dict length\n"); return FALSE; } + *end_pos = pos; } break; diff --git a/dbus/dbus-test.c b/dbus/dbus-test.c index 2d1b5477..f7d1c4ef 100644 --- a/dbus/dbus-test.c +++ b/dbus/dbus-test.c @@ -100,32 +100,6 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir) check_memleaks (); - printf ("%s: running keyring tests\n", "dbus-test"); - if (!_dbus_keyring_test ()) - die ("keyring"); - - check_memleaks (); - -#if 0 - printf ("%s: running md5 tests\n", "dbus-test"); - if (!_dbus_md5_test ()) - die ("md5"); - - check_memleaks (); -#endif - - printf ("%s: running SHA-1 tests\n", "dbus-test"); - if (!_dbus_sha_test (test_data_dir)) - die ("SHA-1"); - - check_memleaks (); - - printf ("%s: running auth tests\n", "dbus-test"); - if (!_dbus_auth_test (test_data_dir)) - die ("auth"); - - check_memleaks (); - printf ("%s: running address parse tests\n", "dbus-test"); if (!_dbus_address_test ()) die ("address parsing"); @@ -162,6 +136,32 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir) check_memleaks (); + printf ("%s: running keyring tests\n", "dbus-test"); + if (!_dbus_keyring_test ()) + die ("keyring"); + + check_memleaks (); + +#if 0 + printf ("%s: running md5 tests\n", "dbus-test"); + if (!_dbus_md5_test ()) + die ("md5"); + + check_memleaks (); +#endif + + printf ("%s: running SHA-1 tests\n", "dbus-test"); + if (!_dbus_sha_test (test_data_dir)) + die ("SHA-1"); + + check_memleaks (); + + printf ("%s: running auth tests\n", "dbus-test"); + if (!_dbus_auth_test (test_data_dir)) + die ("auth"); + + check_memleaks (); + printf ("%s: completed successfully\n", "dbus-test"); #else printf ("Not compiled with unit tests, not running any\n"); -- cgit