From 1f77c0a18896c2661bd3aa65ecfd47a31efcb87a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 31 Aug 2018 18:50:37 +0100 Subject: [PATCH] tests: Make it clearer that we avoid overflowing fixed-length buffers Signed-off-by: Simon McVittie --- dbus/dbus-marshal-recursive-util.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dbus/dbus-marshal-recursive-util.c b/dbus/dbus-marshal-recursive-util.c index 97bc5fe3f..704757b79 100644 --- a/dbus/dbus-marshal-recursive-util.c +++ b/dbus/dbus-marshal-recursive-util.c @@ -2145,6 +2145,8 @@ int16_write_multi (TestTypeNode *node, dbus_int16_t *v_ARRAY_INT16 = values; int i; + _dbus_assert (count <= MAX_MULTI_COUNT); + for (i = 0; i < count; ++i) values[i] = int16_from_seed (seed + i); @@ -2270,6 +2272,8 @@ int32_write_multi (TestTypeNode *node, dbus_int32_t *v_ARRAY_INT32 = values; int i; + _dbus_assert (count <= MAX_MULTI_COUNT); + for (i = 0; i < count; ++i) values[i] = int32_from_seed (seed + i); @@ -2380,7 +2384,10 @@ string_from_seed (char *buf, int i; unsigned char v; - _dbus_assert (len < MAX_SAMPLE_STRING_LEN); + /* Callers use a buffer of length MAX_SAMPLE_STRING_LEN + 1, which is + * enough for MAX_SAMPLE_STRING_LEN bytes of actual string payload, + * plus the NUL terminator */ + _dbus_assert (len + 2 <= MAX_SAMPLE_STRING_LEN); /* vary the length slightly, though we also have multiple string * value types for this, varying it here tests the set_value code -- 2.47.3