An integer overflow in length calculation could lead to
under-allocation and buffer overcopy.
Signed-off-by: Timo tp Preißl <t.preissl@proton.me>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <simon.glass@canonical.com>
Reviewed-by: João Marcos Costa <joaomarcos.costa@bootlin.com>
{
char *result;
int i, length = 0, offset = 0;
+ size_t alloc;
length = sqfs_get_tokens_length(token_list, token_count);
- result = malloc(length + 1);
+ if (__builtin_add_overflow(length, 1, &alloc))
+ return 0;
+
+ result = malloc(alloc);
if (!result)
return NULL;