All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Colin King <colin.king@canonical.com>
Cc: 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: Fri, 12 Aug 2016 18:55:17 -0300	[thread overview]
Message-ID: <20160812215517.GO27651@kernel.org> (raw)
In-Reply-To: <1471038296-12956-1-git-send-email-colin.king@canonical.com>

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

- 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

  reply	other threads:[~2016-08-12 21:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-12 21:44 [PATCH] perf probe: check for dup and fdopen failures Colin King
2016-08-12 21:55 ` Arnaldo Carvalho de Melo [this message]
2016-08-12 23:55   ` Masami Hiramatsu
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=20160812215517.GO27651@kernel.org \
    --to=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=mhiramat@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 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.