]> git.baikalelectronics.ru Git - kernel.git/commit
perf top: Fix events overflow in top command
authorJiri Olsa <jolsa@redhat.com>
Mon, 7 Mar 2011 20:13:40 +0000 (21:13 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 10 Mar 2011 13:54:13 +0000 (10:54 -0300)
commitf2bd83326f4a4c26c10fb9065a4595b74e98426e
tree35687cc87135475ce5be257c878cee6eeaf40f37
parent955fe9514cfe6910ee2e2c18b69b31158b4e26a7
perf top: Fix events overflow in top command

The snprintf function returns number of printed characters even if it
cross the size parameter. So passing enough events via '-e' parameter
will cause segmentation fault.

It's reproduced by following command:

perf top -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}'`

Attached patch is adding SNPRINTF macro that provides the overflow check
and returns actuall number of printed characters.

Reported-by: Han Pingtian <phan@redhat.com>
Cc: Han Pingtian <phan@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1299528821-17521-2-git-send-email-jolsa@redhat.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/top.c