perf tools: Fix buffer overflow error when specifying all tracepoints
authorHan Pingtian <phan@redhat.com>
Thu, 6 Jan 2011 09:39:22 +0000 (17:39 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 6 Jan 2011 20:04:46 +0000 (18:04 -0200)
commitf006d25a15216a483cec71e886786874f66f9452
tree66420a0098c774f4d8c29bb43f81e2ba967c59cb
parent4b95f135f606c87e4056b6d7fd3c5781c818858b
perf tools: Fix buffer overflow error when specifying all tracepoints

I found when specifying all tracepoints with -e to one of subcommand,
such as 'stat', the program will trigger a buffer overflow error, like
this:

*** buffer overflow detected ***: ./perf terminated
======= Backtrace: =========
/lib64/libc.so.6(__fortify_fail+0x37)[0x382cefb2c7]
....

The tracepoints are separated by comma, something like this:

$ perf stat -a -e `perf list |grep Tracepoint|awk -F'[' '{gsub(/[[:space:]]+/,"",$1);array[FNR]=$1}END{outputs=array[1];for (i=2;i<=FNR;i++){ outputs=outputs "," array[i];};print outputs}'`

The root reason of this problem is that store_event_type() is called for all
events, and will overflow the 'filename' at:

    strncat(filename, orgname, strlen(orgname));

This patch fixes it by calling store_event_type() only when the event name has
been found.

LKML-Reference: <20110106093922.GB6713@hpt.nay.redhat.com>
Signed-off-by: Han Pingtian <phan@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/parse-events.c