The function does bounds checking, allocation and copying. In the first
instance, we manually set errno (to ENOMEM?) on failure. The realloc()
call does the same, implicitly.
In practice we don't distinguish between the two failures, so we might
as well stop manually setting errno and always assume ENOMEM in the
caller.
Reference: https://github.com/kmod-project/kmod/issues/244
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/346
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
/* (string vector + NULL) * sizeof(char *) + strbuf_used() */
if (uaddsz_overflow(count, 1, &n) ||
umulsz_overflow(sizeof(char *), n, &vec_size) ||
- uaddsz_overflow(strbuf_used(buf), vec_size, &total_size)) {
- errno = ENOMEM;
+ uaddsz_overflow(strbuf_used(buf), vec_size, &total_size))
return NULL;
- }
vector = realloc(buf->bytes, total_size);
if (vector == NULL)
else if (count > 0) {
*modinfo = strbuf_to_vector(&buf, (size_t)count);
if (*modinfo == NULL) {
- count = -errno;
+ count = -ENOMEM;
ERR(ctx, "strbuf_to_vector: %m\n");
}
}