]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fs/squashfs: sqfs_probe: fix possible memory leak on error
authorRichard Genoud <richard.genoud@posteo.net>
Tue, 3 Nov 2020 11:11:19 +0000 (12:11 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 19 Nov 2020 14:45:49 +0000 (09:45 -0500)
If SquashFS magic number is invalid, there's a memory leak.

Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com>
Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
fs/squashfs/sqfs.c

index d8d4584fbfd19a4a2501532761d978ef57e9e8f7..7d6f0e88e31ef3843e36b85d9363d7dd25709815 100644 (file)
@@ -1090,8 +1090,8 @@ int sqfs_probe(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition
        /* Make sure it has a valid SquashFS magic number*/
        if (get_unaligned_le32(&sblk->s_magic) != SQFS_MAGIC_NUMBER) {
                printf("Bad magic number for SquashFS image.\n");
-               ctxt.cur_dev = NULL;
-               return -EINVAL;
+               ret = -EINVAL;
+               goto error;
        }
 
        ctxt.sblk = sblk;
@@ -1099,12 +1099,16 @@ int sqfs_probe(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition
        ret = sqfs_decompressor_init(&ctxt);
 
        if (ret) {
-               ctxt.cur_dev = NULL;
-               free(ctxt.sblk);
-               return -EINVAL;
+               ret = -EINVAL;
+               goto error;
        }
 
        return 0;
+error:
+       ctxt.cur_dev = NULL;
+       free(ctxt.sblk);
+       ctxt.sblk = NULL;
+       return ret;
 }
 
 static char *sqfs_basename(char *path)