From 4794fdc73c1b1e7e42870989510fb9bd9bab3d5a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 6 Jun 2011 13:50:17 +0100 Subject: [PATCH 1/9] _dbus_type_writer_clear: add function to invalidate a type writer Also add a macro to assert that a type-writer is still valid. --- dbus/dbus-marshal-recursive.c | 17 +++++++++++++++++ dbus/dbus-marshal-recursive.h | 9 +++++++++ 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/dbus/dbus-marshal-recursive.c b/dbus/dbus-marshal-recursive.c index 4adfd2e..8bb403c 100644 --- a/dbus/dbus-marshal-recursive.c +++ b/dbus/dbus-marshal-recursive.c @@ -2747,6 +2747,23 @@ _dbus_type_writer_set_enabled (DBusTypeWriter *writer, writer->enabled = enabled != FALSE; } +/** + * Reset the type writer to an invalid state, so that incorrect accesses to it + * can be trapped. + * + * It is safe to call this on any type writer, even one in an indeterminate + * state. + */ +void +_dbus_type_writer_clear (DBusTypeWriter *writer) +{ + /* it doesn't actually matter whether we uninit the other fields: clearing + * the pointers is enough to make invalid accesses crash deterministically, + * and also enough to make _DBUS_ASSERT_TYPE_WRITER fail */ + writer->type_str = NULL; + writer->value_str = NULL; +} + /** @} */ /* end of DBusMarshal group */ /* tests in dbus-marshal-recursive-util.c */ diff --git a/dbus/dbus-marshal-recursive.h b/dbus/dbus-marshal-recursive.h index acbfd73..1268910 100644 --- a/dbus/dbus-marshal-recursive.h +++ b/dbus/dbus-marshal-recursive.h @@ -156,6 +156,7 @@ void _dbus_type_writer_init_values_only (DBusTypeWriter *write int type_pos, DBusString *value_str, int value_pos); +void _dbus_type_writer_clear (DBusTypeWriter *writer); dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer, int type, const void *value); @@ -177,5 +178,13 @@ dbus_bool_t _dbus_type_writer_append_array (DBusTypeWriter *write dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer, DBusTypeReader *reader); +/** + * Assert that a type-writer has been initialized with _dbus_type_writer_init. + */ +#define _DBUS_ASSERT_TYPE_WRITER(writer) \ + do { \ + _dbus_assert ((writer) != NULL); \ + _dbus_assert ((writer)->value_str != NULL); \ + } while (0) #endif /* DBUS_MARSHAL_RECURSIVE_H */ -- 1.7.6.3