aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Phlipot <cphlipot0@gmail.com>2018-08-29 22:19:50 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-08-30 13:51:45 -0400
commitc9f23d2bc21cb263ae931f3e264d003d746107bb (patch)
treeae9b04c4000e4131a043f79aa67ba2667dabac25
parenta72f64261359b7451f8478f2a2bf357b4e6c757f (diff)
perf event-parse: Use fixed size string for comms
Some implementations of libc do not support the 'm' width modifier as part of the scanf string format specifier. This can cause the parsing to fail. Since the parser never checks if the scanf parsing was successesful, this can result in a crash. Change the comm string to be allocated as a fixed size instead of dynamically using 'm' scanf width modifier. This can be safely done since comm size is limited to 16 bytes by TASK_COMM_LEN within the kernel. This change prevents perf from crashing when linked against bionic as well as reduces the total number of heap allocations and frees invoked while accomplishing the same task. Signed-off-by: Chris Phlipot <cphlipot0@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20180830021950.15563-1-cphlipot0@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/trace-event-parse.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index 920b1d58a068..e76214f8d596 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -164,16 +164,15 @@ void parse_ftrace_printk(struct tep_handle *pevent,
164void parse_saved_cmdline(struct tep_handle *pevent, 164void parse_saved_cmdline(struct tep_handle *pevent,
165 char *file, unsigned int size __maybe_unused) 165 char *file, unsigned int size __maybe_unused)
166{ 166{
167 char *comm; 167 char comm[17]; /* Max comm length in the kernel is 16. */
168 char *line; 168 char *line;
169 char *next = NULL; 169 char *next = NULL;
170 int pid; 170 int pid;
171 171
172 line = strtok_r(file, "\n", &next); 172 line = strtok_r(file, "\n", &next);
173 while (line) { 173 while (line) {
174 sscanf(line, "%d %ms", &pid, &comm); 174 if (sscanf(line, "%d %16s", &pid, comm) == 2)
175 tep_register_comm(pevent, comm, pid); 175 tep_register_comm(pevent, comm, pid);
176 free(comm);
177 line = strtok_r(NULL, "\n", &next); 176 line = strtok_r(NULL, "\n", &next);
178 } 177 }
179} 178}