aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2009-10-20 19:19:35 -0400
committerIngo Molnar <mingo@elte.hu>2009-10-21 07:39:57 -0400
commit4e3b799d7dbb2a12ca8dca8d3594d32095772973 (patch)
tree784404eadda2611489b1fec26d42cd2563d7d407 /tools/perf
parent60d526f7fa6246b8e32d5b45610d625a5608d988 (diff)
perf tools: Use strsep() over strtok_r() for parsing single line
The second argument in the strtok_r() function is not to be used generically and can have different implementations. Currently the function parsing of the perf trace code uses the second argument to copy data from. This can crash the tool or just have unpredictable results. The correct solution is to use strsep() which has a defined result. I also added a check to see if the result was correct, and will break out of the loop in case it fails to parse as expected. Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> LKML-Reference: <20091020232034.237814877@goodmis.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/trace-event-parse.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index 4b61b497040e..eae560503086 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -286,16 +286,19 @@ void parse_ftrace_printk(char *file, unsigned int size __unused)
286 char *line; 286 char *line;
287 char *next = NULL; 287 char *next = NULL;
288 char *addr_str; 288 char *addr_str;
289 char *fmt;
290 int i; 289 int i;
291 290
292 line = strtok_r(file, "\n", &next); 291 line = strtok_r(file, "\n", &next);
293 while (line) { 292 while (line) {
293 addr_str = strsep(&line, ":");
294 if (!line) {
295 warning("error parsing print strings");
296 break;
297 }
294 item = malloc_or_die(sizeof(*item)); 298 item = malloc_or_die(sizeof(*item));
295 addr_str = strtok_r(line, ":", &fmt);
296 item->addr = strtoull(addr_str, NULL, 16); 299 item->addr = strtoull(addr_str, NULL, 16);
297 /* fmt still has a space, skip it */ 300 /* fmt still has a space, skip it */
298 item->printk = strdup(fmt+1); 301 item->printk = strdup(line+1);
299 item->next = list; 302 item->next = list;
300 list = item; 303 list = item;
301 line = strtok_r(NULL, "\n", &next); 304 line = strtok_r(NULL, "\n", &next);