Skip to contentSkip to conversation

fs: fat: Fix possible double free of fatbuf

PATCH New Andrew F. Davis 2 participants 2 messages May 16, 2019 – May 29, 2019 VFAT/FAT/msdos filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: fat: Fix possible double free of fatbuf

fat_itr_root() allocates fatbuf so we free it on the exit path, if the function fails we should not free it, check the return value and skip freeing if the function fails.

---
 fs/fat/fat.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/fat/fat.c +5 -4
index c5997c2173..06c8ed14bd 100644
@@ -1134,11 +1134,12 @@ int fat_size(const char *filename, loff_t *size)
 		 * expected to fail if passed a directory path:
 		 */
 		free(fsdata.fatbuf);
-		fat_itr_root(itr, &fsdata);
-		if (!fat_itr_resolve(itr, filename, TYPE_DIR)) {
+		ret = fat_itr_root(itr, &fsdata);
+		if (ret)
+			goto out_free_itr;
+		ret = fat_itr_resolve(itr, filename, TYPE_DIR);
+		if (!ret)
 			*size = 0;
-			ret = 0;
-		}
 		goto out_free_both;
 	}
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 fs: fat: Fix possible double free of fatbuf

Quoted 5 lines · Andrew F. Davis

fat_itr_root() allocates fatbuf so we free it on the exit path, if the function fails we should not free it, check the return value and skip freeing if the function fails.

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: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190529/a69554b3/attachment.sig>