fs/squashfs: sqfs_close/sqfs_read_sblk: set ctxt.sblk to NULL after free 89/250889/1
authorRichard Genoud <richard.genoud@posteo.net>
Tue, 24 Nov 2020 17:07:52 +0000 (18:07 +0100)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 5 Jan 2021 07:12:53 +0000 (16:12 +0900)
This will prevent a double free error if sqfs_close() is called twice.

Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
[jh80.chung: cherry picked from mainline commit 7e932ac790b3615a67a3c24041c194aa748c0d98]
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Change-Id: I31166f8f9d6ec6d4772e7b51b5d0bb8d20ef1a4b

fs/squashfs/sqfs.c

index 8064756..4e11727 100644 (file)
@@ -49,6 +49,7 @@ static int sqfs_read_sblk(struct squashfs_super_block **sblk)
 
        if (sqfs_disk_read(0, 1, *sblk) != 1) {
                free(*sblk);
+               sblk = NULL;
                return -EINVAL;
        }
 
@@ -1692,9 +1693,10 @@ free_strings:
 
 void sqfs_close(void)
 {
+       sqfs_decompressor_cleanup(&ctxt);
        free(ctxt.sblk);
+       ctxt.sblk = NULL;
        ctxt.cur_dev = NULL;
-       sqfs_decompressor_cleanup(&ctxt);
 }
 
 void sqfs_closedir(struct fs_dir_stream *dirs)