Remove now-unused _dbus_validate_signature()
authorSimon McVittie <smcv@collabora.com>
Mon, 3 Jul 2017 18:29:31 +0000 (19:29 +0100)
committerSimon McVittie <smcv@collabora.com>
Tue, 4 Jul 2017 16:07:32 +0000 (17:07 +0100)
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 <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101568

dbus/dbus-marshal-validate-util.c
dbus/dbus-marshal-validate.c
dbus/dbus-marshal-validate.h

index 2bd798a..4174ae4 100644 (file)
@@ -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");
index c363d3d..6a3bf46 100644 (file)
@@ -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() */
index 2b79fac..df8e567 100644 (file)
@@ -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)