All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Arnaldo Carvalho de Melo <acme@infradead.org>
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: Wed, 22 Dec 2010 13:57:39 +0900	[thread overview]
Message-ID: <4D118543.3040007@hitachi.com> (raw)
In-Reply-To: <20101221182321.GA15683@ghostprotocols.net>

(2010/12/22 3:23), Arnaldo Carvalho de Melo wrote:
> 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?

Without dupstr, strlist(str_node__delete) will not release
allocated buffer... And we have to release it if the parsed
string started with "file://" after loading file.

(Ah, and there is a same problem in strlist__load() too...)

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

Yeah, it could be, but in that case, we need changing code
wider.
I think this is the simplest solution. :)

(Of course, we have to check dupstr flag on top of strlist__load too.)

Thank you,

>>  	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;

-- 
Masami HIRAMATSU
2nd Dept. Linux Technology Center
Hitachi, Ltd., Systems Development Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com

  reply	other threads:[~2010-12-22  4:57 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
2010-12-22  4:57     ` Masami Hiramatsu [this message]
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=4D118543.3040007@hitachi.com \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=2nddept-manager@sdl.hitachi.co.jp \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --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 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.