From: Simon McVittie Date: Fri, 31 Aug 2018 17:50:37 +0000 (+0100) Subject: tests: Make it clearer that we avoid overflowing fixed-length buffers X-Git-Tag: dbus-1.13.8~23^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f77c0a18896c2661bd3aa65ecfd47a31efcb87a;p=thirdparty%2Fdbus.git tests: Make it clearer that we avoid overflowing fixed-length buffers Signed-off-by: Simon McVittie --- 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