All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/1] fs: fat: memory leak in fat_unlink()
@ 2018-10-02  4:58 Heinrich Schuchardt
  2018-10-02  6:39 ` AKASHI Takahiro
  2018-10-07  0:29 ` [U-Boot] [U-Boot,1/1] " Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2018-10-02  4:58 UTC (permalink / raw)
  To: u-boot

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

This addresses Coverity Scan CID 184086.

Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 fs/fat/fat_write.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 4286a0a847..b1ed0e6734 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -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);
-- 
2.19.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH 1/1] fs: fat: memory leak in fat_unlink()
  2018-10-02  4:58 [U-Boot] [PATCH 1/1] fs: fat: memory leak in fat_unlink() Heinrich Schuchardt
@ 2018-10-02  6:39 ` AKASHI Takahiro
  2018-10-07  0:29 ` [U-Boot] [U-Boot,1/1] " Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: AKASHI Takahiro @ 2018-10-02  6:39 UTC (permalink / raw)
  To: u-boot

On Tue, Oct 02, 2018 at 06:58:00AM +0200, Heinrich Schuchardt wrote:
> 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


> Reported-by: Tom Rini <trini@konsulko.com>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  fs/fat/fat_write.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
> index 4286a0a847..b1ed0e6734 100644
> --- a/fs/fat/fat_write.c
> +++ b/fs/fat/fat_write.c
> @@ -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);
> -- 
> 2.19.0
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] [U-Boot,1/1] fs: fat: memory leak in fat_unlink()
  2018-10-02  4:58 [U-Boot] [PATCH 1/1] fs: fat: memory leak in fat_unlink() Heinrich Schuchardt
  2018-10-02  6:39 ` AKASHI Takahiro
@ 2018-10-07  0:29 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2018-10-07  0:29 UTC (permalink / raw)
  To: u-boot

On Tue, Oct 02, 2018 at 06:58:00AM +0200, Heinrich Schuchardt wrote:

> Do not leak filename_copy in case of error.
> Catch out of memory when calling strdup.
> 
> This addresses Coverity Scan CID 184086.
> 
> Reported-by: Tom Rini <trini@konsulko.com>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Applied to u-boot/master, thanks!

-- 
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>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-10-07  0:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-02  4:58 [U-Boot] [PATCH 1/1] fs: fat: memory leak in fat_unlink() Heinrich Schuchardt
2018-10-02  6:39 ` AKASHI Takahiro
2018-10-07  0:29 ` [U-Boot] [U-Boot,1/1] " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.