summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-03-10 18:59:26 (GMT)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-03-10 18:59:29 (GMT)
commit4012b009557fe8796a8e5d343548821c70322dd3 (patch)
tree76c32940453b0232ac4c646ba6020419ba5a64b1
parentd60cc351feb6a06226ff76d4caba35bf785bfb80 (diff)
parenta9cbeecfcc2fee6e89bf1f5e1dd2a8f0fe860c55 (diff)
Merge branch 'validate-when-sending-16338' into dbus-1.4
Reviewed-by: Will Thompson <will.thompson@collabora.co.uk>
-rw-r--r--dbus/dbus-marshal-validate.c2
-rw-r--r--dbus/dbus-marshal-validate.h4
-rw-r--r--dbus/dbus-message.c46
3 files changed, 52 insertions, 0 deletions
diff --git a/dbus/dbus-marshal-validate.c b/dbus/dbus-marshal-validate.c
index b457997..4304467 100644
--- a/dbus/dbus-marshal-validate.c
+++ b/dbus/dbus-marshal-validate.c
@@ -1221,6 +1221,8 @@ DEFINE_DBUS_NAME_CHECK(error_name)
DEFINE_DBUS_NAME_CHECK(bus_name)
/** define _dbus_check_is_valid_signature() */
DEFINE_DBUS_NAME_CHECK(signature)
+/** define _dbus_check_is_valid_utf8() */
+DEFINE_DBUS_NAME_CHECK(utf8)
/** @} */
diff --git a/dbus/dbus-marshal-validate.h b/dbus/dbus-marshal-validate.h
index 8947a2a..1d2e26b 100644
--- a/dbus/dbus-marshal-validate.h
+++ b/dbus/dbus-marshal-validate.h
@@ -147,6 +147,8 @@ dbus_bool_t _dbus_validate_bus_name (const DBusString *str,
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)
#ifdef DBUS_DISABLE_CHECKS
@@ -193,6 +195,8 @@ DECLARE_DBUS_NAME_CHECK(error_name);
DECLARE_DBUS_NAME_CHECK(bus_name);
/** defines _dbus_check_is_valid_signature() */
DECLARE_DBUS_NAME_CHECK(signature);
+/** defines _dbus_check_is_valid_utf8() */
+DECLARE_DBUS_NAME_CHECK(utf8);
/** @} */
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 442ec2a..075ff31 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -2515,6 +2515,39 @@ dbus_message_iter_append_basic (DBusMessageIter *iter,
_dbus_return_val_if_fail (dbus_type_is_basic (type), FALSE);
_dbus_return_val_if_fail (value != NULL, FALSE);
+#ifndef DBUS_DISABLE_CHECKS
+ switch (type)
+ {
+ const char * const *string_p;
+ const dbus_bool_t *bool_p;
+
+ case DBUS_TYPE_STRING:
+ string_p = value;
+ _dbus_return_val_if_fail (_dbus_check_is_valid_utf8 (*string_p), FALSE);
+ break;
+
+ case DBUS_TYPE_OBJECT_PATH:
+ string_p = value;
+ _dbus_return_val_if_fail (_dbus_check_is_valid_path (*string_p), FALSE);
+ break;
+
+ case DBUS_TYPE_SIGNATURE:
+ string_p = value;
+ _dbus_return_val_if_fail (_dbus_check_is_valid_signature (*string_p), FALSE);
+ break;
+
+ case DBUS_TYPE_BOOLEAN:
+ bool_p = value;
+ _dbus_return_val_if_fail (*bool_p == 0 || *bool_p == 1, FALSE);
+ break;
+
+ default:
+ {
+ /* nothing to check, all possible values are allowed */
+ }
+ }
+#endif
+
if (!_dbus_message_iter_open_signature (real))
return FALSE;
@@ -2627,6 +2660,19 @@ dbus_message_iter_append_fixed_array (DBusMessageIter *iter,
DBUS_MAXIMUM_ARRAY_LENGTH / _dbus_type_get_alignment (element_type),
FALSE);
+#ifndef DBUS_DISABLE_CHECKS
+ if (element_type == DBUS_TYPE_BOOLEAN)
+ {
+ const dbus_bool_t * const *bools = value;
+ int i;
+
+ for (i = 0; i < n_elements; i++)
+ {
+ _dbus_return_val_if_fail ((*bools)[i] == 0 || (*bools)[i] == 1, FALSE);
+ }
+ }
+#endif
+
ret = _dbus_type_writer_write_fixed_multi (&real->u.writer, element_type, value, n_elements);
return ret;