nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Jeff Moyer <jmoyer@redhat.com>
To: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Cc: linux-nvdimm@lists.01.org, linfeilong <linfeilong@huawei.com>
Subject: Re: [ndctl PATCH 4/8] dimm: fix potential fd leakage in dimm_action()
Date: Fri, 20 Nov 2020 11:36:59 -0500	[thread overview]
Message-ID: <x49r1oom1ck.fsf@segfault.boston.devel.redhat.com> (raw)
In-Reply-To: <1ca17cf4-a5fd-786d-fa50-8ed09ccd55e4@huawei.com> (Zhiqiang Liu's message of "Fri, 6 Nov 2020 17:26:12 +0800")

Zhiqiang Liu <liuzhiqiang26@huawei.com> writes:

> In dimm_action(), actx.f_out and actx.f_in may be set by calling
> fopen(). If exceptions occur, we will directly goto out tag.
> However, we did not close actx.f_out|actx.f_in in out tag, which
> will cause fd leakage.
>
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> ---
>  ndctl/dimm.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/ndctl/dimm.c b/ndctl/dimm.c
> index 90eb0b8..2f52cda 100644
> --- a/ndctl/dimm.c
> +++ b/ndctl/dimm.c
> @@ -1352,7 +1352,7 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx,
>  			fprintf(stderr, "failed to open: %s: (%s)\n",
>  					param.infile, strerror(errno));
>  			rc = -errno;
> -			goto out;
> +			goto out_close_fout;
>  		}
>  	}
>
> @@ -1371,7 +1371,7 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx,
>  		fprintf(stderr, "'%s' is not a valid label version\n",
>  				param.labelversion);
>  		rc = -EINVAL;
> -		goto out;
> +		goto out_close_fin_fout;
>  	}
>
>  	rc = 0;
> @@ -1423,12 +1423,14 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx,
>  		util_display_json_array(actx.f_out, actx.jdimms, flags);
>  	}
>
> -	if (actx.f_out != stdout)
> -		fclose(actx.f_out);
> -
> + out_close_fin_fout:
>  	if (actx.f_in != stdin)
>  		fclose(actx.f_in);
>
> + out_close_fout:
> +	if (actx.f_out != stdout)
> +		fclose(actx.f_out);
> +
>   out:
>  	/*
>  	 * count if some actions succeeded, 0 if none were attempted,

Acked-by: Jeff Moyer <jmoyer@redhat.com>
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

  reply	other threads:[~2020-11-20 16:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-06  9:23 [ndctl PATCH 0/8] fix serverl issues reported by Coverity Zhiqiang Liu
2020-11-06  9:24 ` [ndctl PATCH 1/8] namespace: check whether pfn|dax|btt is NULL in setup_namespace Zhiqiang Liu
2020-11-20 16:29   ` Jeff Moyer
2020-11-06  9:25 ` [ndctl PATCH 2/8] lib/libndctl: fix memory leakage problem in add_bus Zhiqiang Liu
2020-11-20 16:31   ` Jeff Moyer
2020-11-06  9:25 ` [ndctl PATCH 3/8] libdaxctl: fix memory leakage in add_dax_region() Zhiqiang Liu
2020-11-20 16:33   ` Jeff Moyer
2020-11-06  9:26 ` [ndctl PATCH 4/8] dimm: fix potential fd leakage in dimm_action() Zhiqiang Liu
2020-11-20 16:36   ` Jeff Moyer [this message]
2020-11-06  9:26 ` [ndctl PATCH 5/8] util/help: check whether strdup returns NULL in exec_man_konqueror Zhiqiang Liu
2020-11-06  9:27 ` [ndctl PATCH 6/8] lib/inject: check whether cmd is created successfully Zhiqiang Liu
2020-12-17  3:33   ` Verma, Vishal L
2020-12-17  6:19     ` Zhiqiang Liu
2020-11-06  9:27 ` [ndctl PATCH 7/8] Check whether ndctl_btt_get_namespace returns NULL in callers Zhiqiang Liu
2020-11-06  9:28 ` [ndctl PATCH 8/8] Check whether seed is NULL in validate_namespace_options Zhiqiang Liu
2020-11-10 10:58 ` [ndctl PATCH 0/8] fix serverl issues reported by Coverity Zhiqiang Liu
2020-11-20  2:45 ` Zhiqiang Liu
2020-11-20  2:47   ` Verma, Vishal L
2020-11-20  3:01     ` Zhiqiang Liu
2020-11-20 16:45 ` Jeff Moyer
2020-11-23  0:47   ` Zhiqiang Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=x49r1oom1ck.fsf@segfault.boston.devel.redhat.com \
    --to=jmoyer@redhat.com \
    --cc=linfeilong@huawei.com \
    --cc=linux-nvdimm@lists.01.org \
    --cc=liuzhiqiang26@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).