[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1356599507-14226-8-git-send-email-namhyung@kernel.org>
Date: Thu, 27 Dec 2012 18:11:44 +0900
From: Namhyung Kim <namhyung@...nel.org>
To: Arnaldo Carvalho de Melo <acme@...stprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Paul Mackerras <paulus@...ba.org>,
Ingo Molnar <mingo@...nel.org>,
LKML <linux-kernel@...r.kernel.org>,
David Ahern <dsahern@...il.com>, Jiri Olsa <jolsa@...hat.com>,
Namhyung Kim <namhyung.kim@....com>,
Stephane Eranian <eranian@...gle.com>
Subject: [PATCH 07/10] perf sort: Check return value of strdup()
From: Namhyung Kim <namhyung.kim@....com>
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.
Cc: Stephane Eranian <eranian@...gle.com>
Signed-off-by: Namhyung Kim <namhyung@...nel.org>
---
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 c02964cabdd0..9f827e25a2b5 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -552,6 +552,11 @@ void setup_sorting(const char * const usagestr[], const struct option *opts)
{
char *tmp, *tok, *str = strdup(sort_order);
+ if (str == NULL) {
+ error("Not enough memory to setup sort keys");
+ exit(-1);
+ }
+
for (tok = strtok_r(str, ", ", &tmp);
tok; tok = strtok_r(NULL, ", ", &tmp)) {
if (sort_dimension__add(tok) < 0) {
--
1.7.11.7
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists