mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Colin King <colin.king@canonical.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
	Wang Nan <wangnan0@huawei.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf probe: check for dup and fdopen failures
Date: Sat, 13 Aug 2016 08:55:54 +0900	[thread overview]
Message-ID: <20160813085554.3223c0c346a07ea0542c0d02@kernel.org> (raw)
In-Reply-To: <20160812215517.GO27651@kernel.org>

On Fri, 12 Aug 2016 18:55:17 -0300
Arnaldo Carvalho de Melo <acme@kernel.org> wrote:

> Em Fri, Aug 12, 2016 at 10:44:56PM +0100, Colin King escreveu:
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > dup and fdopen can potentially fail, so add some extra
> > error handling checks rather than assuming they always work.

Thanks, I forgot to handle that.

> > 
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> >  tools/perf/util/probe-file.c | 16 ++++++++++++----
> >  1 file changed, 12 insertions(+), 4 deletions(-)
> > 
> > diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
> > index 9aed9c3..f3df939 100644
> > --- a/tools/perf/util/probe-file.c
> > +++ b/tools/perf/util/probe-file.c
> > @@ -133,7 +133,7 @@ int probe_file__open_both(int *kfd, int *ufd, int flag)
> >  /* Get raw string list of current kprobe_events  or uprobe_events */
> >  struct strlist *probe_file__get_rawlist(int fd)
> >  {
> > -	int ret, idx;
> > +	int ret, idx, fddup;
> >  	FILE *fp;
> >  	char buf[MAX_CMDLEN];
> >  	char *p;
> > @@ -144,7 +144,12 @@ struct strlist *probe_file__get_rawlist(int fd)
> >  
> >  	sl = strlist__new(NULL, NULL);
> >  
> > -	fp = fdopen(dup(fd), "r");
> > +	fddup = dup(fd);
> > +	if (fddup < 0)
> > +		return NULL;
> > +	fp = fdopen(fddup, "r");
> > +	if (!fp)
> 
> here we leak fddup, no?
> 
> > +		return NULL;
> 
> I.e. this should be:
> 
> 	if (!fp) {
> 		close(fddup);
> 		return NULL;
> 	}
> 
> Ack?

Correct, it should be closed. So both fixes look good to me.

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Thanks!


> 
> - Arnaldo
> 
> >  	while (!feof(fp)) {
> >  		p = fgets(buf, MAX_CMDLEN, fp);
> >  		if (!p)
> > @@ -447,10 +452,13 @@ static int probe_cache__load(struct probe_cache *pcache)
> >  {
> >  	struct probe_cache_entry *entry = NULL;
> >  	char buf[MAX_CMDLEN], *p;
> > -	int ret = 0;
> > +	int ret = 0, fddup;
> >  	FILE *fp;
> >  
> > -	fp = fdopen(dup(pcache->fd), "r");
> > +	fddup = dup(pcache->fd);
> > +	if (fddup < 0)
> > +		return -errno;
> > +	fp = fdopen(fddup, "r");
> >  	if (!fp)
> >  		return -EINVAL;
> >  
> > -- 
> > 2.8.1


-- 
Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2016-08-12 23:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-12 21:44 Colin King
2016-08-12 21:55 ` Arnaldo Carvalho de Melo
2016-08-12 23:55   ` Masami Hiramatsu [this message]
2016-08-16 18:16 ` [tip:perf/urgent] perf probe: Check " tip-bot for Colin Ian King

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=20160813085554.3223c0c346a07ea0542c0d02@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=colin.king@canonical.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=wangnan0@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

all inboxes | Powered by JetHome®