[tip:perf/core] perf sort: Check return value of strdup()

From: tip-bot for Namhyung Kim
Date: Wed Feb 06 2013 - 17:06:21 EST


Commit-ID: 5936f54d6ca2857d81188dcdff8c61b8fc482f53
Gitweb: http://git.kernel.org/tip/5936f54d6ca2857d81188dcdff8c61b8fc482f53
Author: Namhyung Kim <namhyung.kim@xxxxxxx>
AuthorDate: Wed, 6 Feb 2013 14:57:17 +0900
Committer: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
CommitDate: Wed, 6 Feb 2013 18:09:26 -0300

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 <namhyung@xxxxxxxxxx>
Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Stephane Eranian <eranian@xxxxxxxxxx>
Link: http://lkml.kernel.org/r/1360130237-9963-3-git-send-email-namhyung@xxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/sort.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index d8b4882..d41926c 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -570,6 +570,11 @@ int setup_sorting(void)
char *tmp, *tok, *str = strdup(sort_order);
int ret = 0;

+ if (str == NULL) {
+ error("Not enough memory to setup sort keys");
+ return -ENOMEM;
+ }
+
for (tok = strtok_r(str, ", ", &tmp);
tok; tok = strtok_r(NULL, ", ", &tmp)) {
ret = sort_dimension__add(tok);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/