[PATCH v2 21/28] fs/squashfs: sqfs_probe: fix possible memory leak on error

João Marcos Costa jmcosta944 at gmail.com
Tue Nov 3 13:46:12 CET 2020


Reviewed-by Joao Marcos Costa <jmcosta944 at gmail.com>

Em ter., 3 de nov. de 2020 às 08:12, Richard Genoud <
richard.genoud at posteo.net> escreveu:

> If SquashFS magic number is invalid, there's a memory leak.
>
> Signed-off-by: Richard Genoud <richard.genoud at posteo.net>
> ---
>  fs/squashfs/sqfs.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
> index d8d4584fbfd..7d6f0e88e31 100644
> --- a/fs/squashfs/sqfs.c
> +++ b/fs/squashfs/sqfs.c
> @@ -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)
>


-- 
Atenciosamente,
João Marcos Costa

www.linkedin.com/in/jmarcoscosta/
https://github.com/jmarcoscosta


More information about the U-Boot mailing list