[PATCH -tip 2/4] [BUGFIX]perf: Fix strlist__parse_list to handleconst string
From: Masami Hiramatsu
Date:  Fri Dec 17 2010 - 08:16:57 EST
Fix strlist__parse_list to handle const string. Without
this patch, strlist__parse_list() causes SEGV when
caller passes a constant string.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
 tools/perf/util/strlist.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c
index 6783a20..caa7884 100644
--- a/tools/perf/util/strlist.c
+++ b/tools/perf/util/strlist.c
@@ -136,13 +136,19 @@ static int strlist__parse_list_entry(struct strlist *self, const char *s)
 
 int strlist__parse_list(struct strlist *self, const char *s)
 {
-	char *sep;
+	char *sep, *tmp;
 	int err;
 
+	/* This method requires strdup, because this changes given string */
+	if (!self->dupstr)
+		return -EINVAL;
+
 	while ((sep = strchr(s, ',')) != NULL) {
-		*sep = '\0';
-		err = strlist__parse_list_entry(self, s);
-		*sep = ',';
+		tmp = strndup(s, sep - s);
+		if (tmp == NULL)
+			return -ENOMEM;
+		err = strlist__parse_list_entry(self, tmp);
+		free(tmp);
 		if (err != 0)
 			return err;
 		s = sep + 1;
--
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/