public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Ingo Molnar <mingo@elte.hu>, Steven Rostedt <rostedt@goodmis.org>,
	Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
	linux-kernel@vger.kernel.org, 2nddept-manager@sdl.hitachi.co.jp,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>
Subject: Re: [PATCH -tip 2/4] [BUGFIX]perf: Fix strlist__parse_list to handle const string
Date: Tue, 21 Dec 2010 16:23:21 -0200	[thread overview]
Message-ID: <20101221182321.GA15683@ghostprotocols.net> (raw)
In-Reply-To: <20101217131206.24123.87394.stgit@ltc236.sdl.hitachi.co.jp>

Em Fri, Dec 17, 2010 at 10:12:06PM +0900, Masami Hiramatsu escreveu:
> Fix strlist__parse_list to handle const string. Without this patch,
> strlist__parse_list() causes SEGV when caller passes a constant
> string.
 
> +++ b/tools/perf/util/strlist.c
> @@ -136,13 +136,19 @@ static int strlist__parse_list_entry(struct strlist *self, const char *s)
>  
>  int strlist__parse_list(struct strlist *self, const char *s)
>  {
> -	char *sep;
> +	char *sep, *tmp;
>  	int err;
>  
> +	/* This method requires strdup, because this changes given string */
> +	if (!self->dupstr)
> +		return -EINVAL;
> +

Why is the above check needed if you solved the problem by strnduping at
each separator?

Wouldn't be better to just stop changing the string by passing the
length to strlist__parse_list_entry, etc?

>  	while ((sep = strchr(s, ',')) != NULL) {
> -		*sep = '\0';
> -		err = strlist__parse_list_entry(self, s);
> -		*sep = ',';
> +		tmp = strndup(s, sep - s);
> +		if (tmp == NULL)
> +			return -ENOMEM;
> +		err = strlist__parse_list_entry(self, tmp);
> +		free(tmp);
>  		if (err != 0)
>  			return err;
>  		s = sep + 1;

  reply	other threads:[~2010-12-21 18:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-17 13:11 [PATCH -tip 0/4][BUGFIX] Perf probe bugfixes Masami Hiramatsu
2010-12-17 13:12 ` [PATCH -tip 1/4] [BUGFIX]perf: Fix lazy wildcard matching Masami Hiramatsu
2010-12-22 11:32   ` [tip:perf/urgent] perf tools: " tip-bot for Masami Hiramatsu
2010-12-17 13:12 ` [PATCH -tip 2/4] [BUGFIX]perf: Fix strlist__parse_list to handle const string Masami Hiramatsu
2010-12-21 18:23   ` Arnaldo Carvalho de Melo [this message]
2010-12-22  4:57     ` Masami Hiramatsu
2010-12-22 14:32       ` Arnaldo Carvalho de Melo
2010-12-17 13:12 ` [PATCH -tip 3/4] [CLEANUP]perf probe: cleanup messages Masami Hiramatsu
2010-12-22 11:30   ` [tip:perf/core] perf probe: Cleanup messages tip-bot for Masami Hiramatsu
2010-12-17 13:12 ` [PATCH -tip 4/4] [BUGFIX]perf probe: Fix to support libdwfl older than 0.148 Masami Hiramatsu
2010-12-22 11:32   ` [tip:perf/urgent] perf " tip-bot for Masami Hiramatsu

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=20101221182321.GA15683@ghostprotocols.net \
    --to=acme@infradead.org \
    --cc=2nddept-manager@sdl.hitachi.co.jp \
    --cc=a.p.zijlstra@chello.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=rostedt@goodmis.org \
    --cc=srikar@linux.vnet.ibm.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