]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
fs/squashfs: Ensure memory is freed by using unwind goto
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Thu, 2 Oct 2025 10:36:09 +0000 (11:36 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 10 Oct 2025 20:27:49 +0000 (14:27 -0600)
Returning immediately from sqfs_read_nest is not consistent with other
error checks in this function and can lead to memory leaks. Instead use
the unwind goto used elsewhere to ensure that the memory is freed.

This issue was found by Smatch.

Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
Acked-by: Quentin Schulz <quentin.schulz@cherry.de>
Reviewed-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
fs/squashfs/sqfs.c

index 2dcdd60f68343f801bd73e318568fb030434ed31..4d3d83b75873f4d66f2dbd544ae6715f66f5d289 100644 (file)
@@ -1584,8 +1584,10 @@ static int sqfs_read_nest(const char *filename, void *buf, loff_t offset,
        table_offset = frag_entry.start - (start * ctxt.cur_dev->blksz);
        n_blks = DIV_ROUND_UP(table_size + table_offset, ctxt.cur_dev->blksz);
 
-       if (__builtin_mul_overflow(n_blks, ctxt.cur_dev->blksz, &buf_size))
-               return -EINVAL;
+       if (__builtin_mul_overflow(n_blks, ctxt.cur_dev->blksz, &buf_size)) {
+               ret = -EINVAL;
+               goto out;
+       }
 
        fragment = malloc_cache_aligned(buf_size);