Skip to contentSkip to conversation

fs: fat: memory leak in fat_unlink()

PATCH New Heinrich Schuchardt 3 participants 3 messages Oct 2, 2018 – Oct 7, 2018 VFAT/FAT/msdos filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: fat: memory leak in fat_unlink()

Do not leak filename_copy in case of error.
Catch out of memory when calling strdup.

This addresses Coverity Scan CID 184086.

---
 fs/fat/fat_write.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/fat/fat_write.c +7 -1
index 4286a0a847..b1ed0e6734 100644
@@ -1263,6 +1263,11 @@ int fat_unlink(const char *filename)
 	char *filename_copy, *dirname, *basename;
 
 	filename_copy = strdup(filename);
+	if (!filename_copy) {
+		printf("Error: allocating memory\n");
+		ret = -ENOMEM;
+		goto exit;
+	}
 	split_filename(filename_copy, &dirname, &basename);
 
 	if (!strcmp(dirname, "/") && !strcmp(basename, "")) {
@@ -1274,7 +1279,8 @@ int fat_unlink(const char *filename)
 	itr = malloc_cache_aligned(sizeof(fat_itr));
 	if (!itr) {
 		printf("Error: allocating memory\n");
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto exit;
 	}
 
 	ret = fat_itr_root(itr, &fsdata);
Signature · 1 line
2.19.0
#1 lore raw

PATCH 1/1 fs: fat: memory leak in fat_unlink()

Quoted 4 lines · Heinrich Schuchardt

Do not leak filename_copy in case of error.
Catch out of memory when calling strdup.

This addresses Coverity Scan CID 184086.

Thanks,
-Takahiro Akashi

Quoted 35 lines
---
 fs/fat/fat_write.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/fat/fat_write.c +7 -1
index 4286a0a847..b1ed0e6734 100644
@@ -1263,6 +1263,11 @@ int fat_unlink(const char *filename)
 	char *filename_copy, *dirname, *basename;
 
 	filename_copy = strdup(filename);
+	if (!filename_copy) {
+		printf("Error: allocating memory\n");
+		ret = -ENOMEM;
+		goto exit;
+	}
 	split_filename(filename_copy, &dirname, &basename);
 
 	if (!strcmp(dirname, "/") && !strcmp(basename, "")) {
@@ -1274,7 +1279,8 @@ int fat_unlink(const char *filename)
 	itr = malloc_cache_aligned(sizeof(fat_itr));
 	if (!itr) {
 		printf("Error: allocating memory\n");
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto exit;
 	}
 
 	ret = fat_itr_root(itr, &fsdata);
Signature · 1 line
2.19.0
#2 lore raw

PATCH 1/1 fs: fat: memory leak in fat_unlink()

In reply to Heinrich Schuchardt
Quoted 7 lines · Heinrich Schuchardt

Do not leak filename_copy in case of error.
Catch out of memory when calling strdup.

This addresses Coverity Scan CID 184086.

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/20181006/b58e7e47/attachment.sig>