The pull loop already avoids out of bounds accesses beyond the end of
the buffer. However, it does not avoid a DoS memory allocation due to
an unreasonably large array size.
Check that the number of specified array elements can be pulled from
buffer, which puts a reasonable upper bound on the subsequent memory
allocation.
Use an initialised dummy variable to avoid static analysers
complaining about uninitialised variables being passed. Variable i
could be reused but that might be confusing, so leave any optimisation
to the compiler.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=16085
Reported-by: Martin Schwenke <mschwenke@ddn.com>
Reported-by: Also Andrew Tridgell (issue 22)
Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Tristan Madani <tristan@talencesecurity.com>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
struct ctdb_vnn_map *val;
size_t offset = 0, np;
uint32_t i;
+ uint32_t dummy = 0;
int ret;
val = talloc(mem_ctx, struct ctdb_vnn_map);
goto done;
}
+ if ((uint64_t)val->size * ctdb_uint32_len(&dummy) > buflen - offset) {
+ ret = EMSGSIZE;
+ goto fail;
+ }
+
val->map = talloc_array(val, uint32_t, val->size);
if (val->map == NULL) {
ret = ENOMEM;