Skip to content

Commit 5936f54

Browse files
Namhyung Kimacmel
Namhyung Kim
authored andcommitted
perf sort: Check return value of strdup()
When setup_sorting() is called, 'str' is passed to strtok_r() but it's not checked to have a valid pointer. As strtok_r() accepts NULL pointer on a first argument and use the third argument in that case, it can cause a trouble since our third argument, tmp, is not initialized. Signed-off-by: Namhyung Kim <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 5530998 commit 5936f54

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tools/perf/util/sort.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,11 @@ int setup_sorting(void)
570570
char *tmp, *tok, *str = strdup(sort_order);
571571
int ret = 0;
572572

573+
if (str == NULL) {
574+
error("Not enough memory to setup sort keys");
575+
return -ENOMEM;
576+
}
577+
573578
for (tok = strtok_r(str, ", ", &tmp);
574579
tok; tok = strtok_r(NULL, ", ", &tmp)) {
575580
ret = sort_dimension__add(tok);

0 commit comments

Comments
 (0)