From 2fecbe759434943a5f03e2796bf41c2f0393017a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 3 Jul 2017 19:29:31 +0100 Subject: [PATCH 6/7] Remove now-unused _dbus_validate_signature() All callers should use _dbus_validate_signature_with_reason() directly. The only remaining callers were this function's own tests. As a side benefit, this commit removes a TODO pointing out that this function did not follow normal DBusString conventions, by considering a length outside the bounds of the DBusString to be an ordinary lack of validity rather than a fatal programming error. Signed-off-by: Simon McVittie --- dbus/dbus-marshal-validate-util.c | 22 ++++++++++++---------- dbus/dbus-marshal-validate.c | 27 --------------------------- dbus/dbus-marshal-validate.h | 4 ---- 3 files changed, 12 insertions(+), 41 deletions(-) diff --git a/dbus/dbus-marshal-validate-util.c b/dbus/dbus-marshal-validate-util.c index 2bd798ac..4174ae42 100644 --- a/dbus/dbus-marshal-validate-util.c +++ b/dbus/dbus-marshal-validate-util.c @@ -436,10 +436,10 @@ _dbus_marshal_validate_test (void) { _dbus_string_init_const (&str, valid_signatures[i]); - if (!_dbus_validate_signature (&str, 0, - _dbus_string_get_length (&str))) + if (_dbus_validate_signature_with_reason (&str, 0, + _dbus_string_get_length (&str)) != DBUS_VALID) { - _dbus_warn ("Signature \"%s\" should have been valid", valid_signatures[i]); + _dbus_warn ("Signature \"%s\" should have been valid and OOM should not have occurred", valid_signatures[i]); _dbus_assert_not_reached ("invalid signature"); } @@ -449,12 +449,18 @@ _dbus_marshal_validate_test (void) i = 0; while (i < (int) _DBUS_N_ELEMENTS (invalid_signatures)) { + DBusValidity validity; + _dbus_string_init_const (&str, invalid_signatures[i]); - if (_dbus_validate_signature (&str, 0, - _dbus_string_get_length (&str))) + validity = _dbus_validate_signature_with_reason (&str, 0, + _dbus_string_get_length (&str)); + + /* Validity values less than DBUS_VALID are OOM or unknown validity. + * TODO: specify in which way each one should be invalid */ + if (validity <= DBUS_VALID) { - _dbus_warn ("Signature \"%s\" should have been invalid", invalid_signatures[i]); + _dbus_warn ("Signature \"%s\" should have been invalid and OOM should not have occurred", invalid_signatures[i]); _dbus_assert_not_reached ("valid signature"); } @@ -474,10 +480,6 @@ _dbus_marshal_validate_test (void) if (_dbus_validate_member (&str, 0, 4)) _dbus_assert_not_reached ("validated too-long string"); - _dbus_string_init_const (&str, "sss"); - if (_dbus_validate_signature (&str, 0, 4)) - _dbus_assert_not_reached ("validated too-long signature"); - /* Validate string exceeding max name length */ if (!_dbus_string_init (&str)) _dbus_assert_not_reached ("no memory"); diff --git a/dbus/dbus-marshal-validate.c b/dbus/dbus-marshal-validate.c index c363d3d5..6a3bf46e 100644 --- a/dbus/dbus-marshal-validate.c +++ b/dbus/dbus-marshal-validate.c @@ -1214,33 +1214,6 @@ _dbus_validate_bus_namespace (const DBusString *str, return _dbus_validate_bus_name_full (str, start, len, TRUE); } -/** - * Checks that the given range of the string is a valid message type - * signature in the D-Bus protocol. - * - * @todo this is inconsistent with most of DBusString in that - * it allows a start,len range that extends past the string end. - * - * @param str the string - * @param start first byte index to check - * @param len number of bytes to check - * @returns #TRUE if the byte range exists and is a valid signature - */ -dbus_bool_t -_dbus_validate_signature (const DBusString *str, - int start, - int len) -{ - _dbus_assert (start >= 0); - _dbus_assert (start <= _dbus_string_get_length (str)); - _dbus_assert (len >= 0); - - if (len > _dbus_string_get_length (str) - start) - return FALSE; - - return _dbus_validate_signature_with_reason (str, start, len) == DBUS_VALID; -} - /** define _dbus_check_is_valid_path() */ DEFINE_DBUS_NAME_CHECK(path) /** define _dbus_check_is_valid_interface() */ diff --git a/dbus/dbus-marshal-validate.h b/dbus/dbus-marshal-validate.h index 2b79facc..df8e5672 100644 --- a/dbus/dbus-marshal-validate.h +++ b/dbus/dbus-marshal-validate.h @@ -155,10 +155,6 @@ DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_validate_bus_namespace (const DBusString *str, int start, int len); -DBUS_PRIVATE_EXPORT -dbus_bool_t _dbus_validate_signature (const DBusString *str, - int start, - int len); /* just to have a name consistent with the above: */ #define _dbus_validate_utf8(s,b,e) _dbus_string_validate_utf8 (s, b, e) -- 2.13.2