summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-string.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2002-12-27 00:44:41 +0000
committerHavoc Pennington <hp@redhat.com>2002-12-27 00:44:41 +0000
commitff5283ab92c668453fd2f28c1715a1e0e9b949f5 (patch)
tree24cf1119e1d203dd08cd4d797ac8640d35451faa /dbus/dbus-string.c
parentf3729626de0093762c9d00a8d02db9c96fbd5bd2 (diff)
2002-12-26 Havoc Pennington <hp@pobox.com>
* dbus/dbus-marshal.h (DBUS_COMPILER_BYTE_ORDER): #ifdef WORDS_BIGENDIAN then compiler byte order is DBUS_BIG_ENDIAN, doh * dbus/dbus-marshal.c: Add macros to do int swapping in-place and avoid swap_bytes() overhead (ignoring possible assembly stuff for now). Main point is because I wanted unpack_uint32 to implement _dbus_verbose_bytes (_dbus_verbose_bytes): new function * dbus/dbus-string.c (_dbus_string_validate_ascii): new function * dbus/dbus-message.c (_dbus_message_loader_get_is_corrupted): add mechanism to handle a corrupt message stream (_dbus_message_loader_new): fix preallocation to only prealloc, not prelengthen * dbus/dbus-string.c (_dbus_string_skip_blank): fix this function (_dbus_string_test): enhance tests for copy/move and fix the functions * dbus/dbus-transport-unix.c: Hold references in more places to avoid reentrancy problems * dbus/dbus-transport.c: ditto * dbus/dbus-connection.c (dbus_connection_dispatch_message): don't leak reference count in no-message case * test/watch.c (do_mainloop): handle adding/removing watches during iteration over the watches. Also, ref the connection/server stored on a watch, so we don't try to mangle a destroyed one. * dbus/dbus-transport-unix.c (do_authentication): perform authentication * dbus/dbus-auth.c (get_state): add a state AUTHENTICATED_WITH_UNUSED_BYTES and return it if required (_dbus_auth_get_unused_bytes): append the unused bytes to the passed in string, rather than prepend * dbus/dbus-transport.c (_dbus_transport_init_base): create the auth conversation DBusAuth * dbus/dbus-transport-unix.c (_dbus_transport_new_for_fd) (_dbus_transport_new_for_domain_socket): when creating a transport, pass in whether it's a client-side or server-side transport so we know which DBusAuth to create
Diffstat (limited to 'dbus/dbus-string.c')
-rw-r--r--dbus/dbus-string.c80
1 files changed, 77 insertions, 3 deletions
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index ef015c68..c4a51d5b 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -723,7 +723,7 @@ open_gap (int len,
memmove (dest->str + insert_at + len,
dest->str + insert_at,
- dest->len - len);
+ dest->len - len - insert_at);
return TRUE;
}
@@ -1139,13 +1139,16 @@ _dbus_string_skip_blank (const DBusString *str,
i = start;
while (i < real->len)
{
- if (real->str[i] != ' ' ||
- real->str[i] != '\t')
+ if (!(real->str[i] == ' ' ||
+ real->str[i] == '\t'))
break;
++i;
}
+ _dbus_assert (i == real->len || !(real->str[i] == ' ' ||
+ real->str[i] == '\t'));
+
if (end)
*end = i;
}
@@ -1586,6 +1589,43 @@ _dbus_string_base64_decode (const DBusString *source,
return TRUE;
}
+/**
+ * Checks that the given range of the string
+ * is valid ASCII. If the given range is not contained
+ * in the string, returns #FALSE.
+ *
+ * @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 all valid ASCII
+ */
+dbus_bool_t
+_dbus_string_validate_ascii (const DBusString *str,
+ int start,
+ int len)
+{
+ const unsigned char *s;
+ const unsigned char *end;
+ DBUS_CONST_STRING_PREAMBLE (str);
+ _dbus_assert (start >= 0);
+ _dbus_assert (len >= 0);
+
+ if ((start + len) > real->len)
+ return FALSE;
+
+ s = real->str + start;
+ end = s + len;
+ while (s != end)
+ {
+ if (*s == '\0' ||
+ ((*s & ~0x7f) != 0))
+ return FALSE;
+
+ ++s;
+ }
+
+ return TRUE;
+}
/** @} */
@@ -1780,6 +1820,24 @@ _dbus_string_test (void)
_dbus_assert (_dbus_string_get_length (&str) == 0);
_dbus_assert (_dbus_string_get_length (&other) == i);
+ if (!_dbus_string_append (&str, "Hello World"))
+ _dbus_assert_not_reached ("could not append to string");
+
+ if (!_dbus_string_move (&str, 0, &other, _dbus_string_get_length (&other)))
+ _dbus_assert_not_reached ("could not move");
+
+ _dbus_assert (_dbus_string_get_length (&str) == 0);
+ _dbus_assert (_dbus_string_get_length (&other) == i * 2);
+
+ if (!_dbus_string_append (&str, "Hello World"))
+ _dbus_assert_not_reached ("could not append to string");
+
+ if (!_dbus_string_move (&str, 0, &other, _dbus_string_get_length (&other) / 2))
+ _dbus_assert_not_reached ("could not move");
+
+ _dbus_assert (_dbus_string_get_length (&str) == 0);
+ _dbus_assert (_dbus_string_get_length (&other) == i * 3);
+
_dbus_string_free (&other);
/* Check copy */
@@ -1797,6 +1855,22 @@ _dbus_string_test (void)
_dbus_assert (_dbus_string_get_length (&str) == i);
_dbus_assert (_dbus_string_get_length (&other) == i);
+
+ if (!_dbus_string_copy (&str, 0, &other, _dbus_string_get_length (&other)))
+ _dbus_assert_not_reached ("could not copy");
+
+ _dbus_assert (_dbus_string_get_length (&str) == i);
+ _dbus_assert (_dbus_string_get_length (&other) == i * 2);
+ _dbus_assert (_dbus_string_equal_c_str (&other,
+ "Hello WorldHello World"));
+
+ if (!_dbus_string_copy (&str, 0, &other, _dbus_string_get_length (&other) / 2))
+ _dbus_assert_not_reached ("could not copy");
+
+ _dbus_assert (_dbus_string_get_length (&str) == i);
+ _dbus_assert (_dbus_string_get_length (&other) == i * 3);
+ _dbus_assert (_dbus_string_equal_c_str (&other,
+ "Hello WorldHello WorldHello World"));
_dbus_string_free (&str);
_dbus_string_free (&other);