Skip to contentSkip to conversation

fs/squashfs: sqfs_close/sqfs_read_sblk: set ctxt.sblk to NULL after free

PATCH New Richard Genoud 2 participants 2 messages Nov 24, 2020 – Dec 3, 2020 SquashFS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/squashfs: sqfs_close/sqfs_read_sblk: set ctxt.sblk to NULL after free

This will prevent a double free error if sqfs_close() is called twice.

---
 fs/squashfs/sqfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/squashfs/sqfs.c +3 -1
index 15208b4dab0..4e6b6058f97 100644
@@ -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;
 	}
 
@@ -1542,9 +1543,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)
#1 lore raw

PATCH 1/1 fs/squashfs: sqfs_close/sqfs_read_sblk: set ctxt.sblk to NULL after free

Quoted 3 lines · Richard Genoud

This will prevent a double free error if sqfs_close() is called twice.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201203/9c3301c6/attachment.sig>