Skip to contentSkip to conversation

perf kvm: Initialize file_name var to fix segfault

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Jan 25, 2013 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  20914ce5b9e1ef4a35f1f09a2c9c8fb8eb1c4d86
Gitweb:     http://git.kernel.org/tip/20914ce5b9e1ef4a35f1f09a2c9c8fb8eb1c4d86
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Wed, 19 Dec 2012 10:59:29 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 24 Jan 2013 16:40:13 -0300

perf kvm: Initialize file_name var to fix segfault

The 3786063 commit:

perf kvm: Rename perf_kvm to perf_kvm_stat

Moved the file_name from inside a local struct var that initialized some of its members, thus zero initializing the not explicitely initialized variables, one of which was 'file_name', to a standalone local variable, but forgot to initialize it explicitely to NULL, so it then got some undefined value, causing a segfault in strdup when it wasn't, by luck, zero.

Fix it by explicitely initializing it to NULL.

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Xiao Guangrong <[email protected]>
---
 tools/perf/builtin-kvm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/builtin-kvm.c +1 -2
index ca3f80e..37a769d 100644
@@ -973,8 +973,7 @@ __cmd_buildid_list(const char *file_name, int argc, const char **argv)
 
 int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
 {
-	const char *file_name;
-
+	const char *file_name = NULL;
 	const struct option kvm_options[] = {
 		OPT_STRING('i', "input", &file_name, "file",
 			   "Input file name"),