fs: prevent integer overflow in sqfs_concat

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>
This commit is contained in:
Timo tp Preißl
2026-01-09 11:24:59 +00:00
committed by Tom Rini
parent c8f0294285
commit 870aff99a2

View File

@@ -255,10 +255,14 @@ static char *sqfs_concat_tokens(char **token_list, int token_count)
{
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;