• J
    perf top: Fix events overflow in top command · b9a46bba
    Jiri Olsa 提交于
    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: NHan 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: NJiri Olsa <jolsa@redhat.com>
    Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
    b9a46bba
top.c 6.4 KB