DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/failsafe: fix resource leak on parse error
@ 2017-08-03 12:34 Gaetan Rivet
  2017-08-03 13:59 ` Gaëtan Rivet
  0 siblings, 1 reply; 2+ messages in thread
From: Gaetan Rivet @ 2017-08-03 12:34 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

If fgets fails, the handle fp is not properly closed.

Coverity issue: 158633
Fixes: a0194d828100 ("net/failsafe: add flexible device definition")

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 drivers/net/failsafe/failsafe_args.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c
index 932e371..3f6430b 100644
--- a/drivers/net/failsafe/failsafe_args.c
+++ b/drivers/net/failsafe/failsafe_args.c
@@ -145,22 +145,20 @@ fs_execute_cmd(struct sub_device *sdev, char *cmdline)
 	/* We only read one line */
 	if (fgets(output, sizeof(output) - 1, fp) == NULL) {
 		DEBUG("Could not read command output");
-		return -ENODEV;
+		ret = -ENODEV;
+		goto ret_pclose;
 	}
 	fs_sanitize_cmdline(output);
 	ret = fs_parse_device(sdev, output);
-	if (ret) {
+	if (ret)
 		ERROR("Parsing device '%s' failed", output);
-		goto ret_pclose;
-	}
 ret_pclose:
-	ret = pclose(fp);
-	if (ret) {
-		ret = errno;
+	if (pclose(fp)) {
+		if (ret == 0)
+			ret = errno;
 		ERROR("pclose: %s", strerror(errno));
-		errno = old_err;
-		return ret;
 	}
+	errno = old_err;
 	return ret;
 }
 
-- 
2.1.4

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

* Re: [dpdk-dev] [PATCH] net/failsafe: fix resource leak on parse error
  2017-08-03 12:34 [dpdk-dev] [PATCH] net/failsafe: fix resource leak on parse error Gaetan Rivet
@ 2017-08-03 13:59 ` Gaëtan Rivet
  0 siblings, 0 replies; 2+ messages in thread
From: Gaëtan Rivet @ 2017-08-03 13:59 UTC (permalink / raw)
  To: dev

self-nack.

This issue has been fixed by Raslan in [1].

[1]: http://dpdk.org/ml/archives/dev/2017-August/072429.html

On Thu, Aug 03, 2017 at 02:34:00PM +0200, Gaetan Rivet wrote:
> If fgets fails, the handle fp is not properly closed.
> 
> Coverity issue: 158633
> Fixes: a0194d828100 ("net/failsafe: add flexible device definition")
> 
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  drivers/net/failsafe/failsafe_args.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c
> index 932e371..3f6430b 100644
> --- a/drivers/net/failsafe/failsafe_args.c
> +++ b/drivers/net/failsafe/failsafe_args.c
> @@ -145,22 +145,20 @@ fs_execute_cmd(struct sub_device *sdev, char *cmdline)
>  	/* We only read one line */
>  	if (fgets(output, sizeof(output) - 1, fp) == NULL) {
>  		DEBUG("Could not read command output");
> -		return -ENODEV;
> +		ret = -ENODEV;
> +		goto ret_pclose;
>  	}
>  	fs_sanitize_cmdline(output);
>  	ret = fs_parse_device(sdev, output);
> -	if (ret) {
> +	if (ret)
>  		ERROR("Parsing device '%s' failed", output);
> -		goto ret_pclose;
> -	}
>  ret_pclose:
> -	ret = pclose(fp);
> -	if (ret) {
> -		ret = errno;
> +	if (pclose(fp)) {
> +		if (ret == 0)
> +			ret = errno;
>  		ERROR("pclose: %s", strerror(errno));
> -		errno = old_err;
> -		return ret;
>  	}
> +	errno = old_err;
>  	return ret;
>  }
>  
> -- 
> 2.1.4
> 

-- 
Gaëtan Rivet
6WIND

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

end of thread, other threads:[~2017-08-03 14:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-03 12:34 [dpdk-dev] [PATCH] net/failsafe: fix resource leak on parse error Gaetan Rivet
2017-08-03 13:59 ` Gaëtan Rivet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).