Skip to content

Commit 8aa8a7c

Browse files
Stephane EranianIngo Molnar
authored andcommitted
perf record: Fix buffer overrun bug in tracepoint_id_to_path()
This patch fixes a buffer overrun bug in tracepoint_id_to_path(). The bug manisfested itself as a memory error reported by perf record. I ran into it with perf sched: $ perf sched rec noploop 2 noploop for 2 seconds [ perf record: Woken up 14 times to write data ] [ perf record: Captured and wrote 42.701 MB perf.data (~1865622 samples) ] Fatal: No memory to alloc tracepoints list It turned out that tracepoint_id_to_path() was reading the tracepoint id using read() but the buffer was not large enough to include the \n terminator for id with 4 digits or more. The patch fixes the problem by extending the buffer to a more reasonable size covering all possible id length include \n terminator. Note that atoll() stops at the first non digit character, thus it is not necessary to clear the buffer between each read. Signed-off-by: Stephane Eranian <[email protected]> Acked-by: Arnaldo Carvalho de Melo <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/20120313155102.GA6465@quad Signed-off-by: Ingo Molnar <[email protected]>
1 parent 87e24f4 commit 8aa8a7c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/perf/util/parse-events.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
165165
struct tracepoint_path *path = NULL;
166166
DIR *sys_dir, *evt_dir;
167167
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
168-
char id_buf[4];
168+
char id_buf[24];
169169
int fd;
170170
u64 id;
171171
char evt_path[MAXPATHLEN];

0 commit comments

Comments
 (0)