aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Yandt <[email protected]>2019-05-14 07:01:00 -0400
committerArnaldo Carvalho de Melo <[email protected]>2019-05-15 16:36:47 -0300
commit30ba5b0e66c872faa416a458d32cc3956ecb548a (patch)
tree646052ffc2fe8738b9b2de1b7307ce02587b99cc
parentbf6d18cffa5f26bd5dc71485c2a2ad0c42a0ce60 (diff)
perf machine: Null-terminate version char array upon fgets(/proc/version) error
If fgets() fails due to any other error besides end-of-file, the version char array may not even be null-terminated. Signed-off-by: Donald Yandt <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Avi Kivity <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Yanmin Zhang <[email protected]> Fixes: a1645ce12adb ("perf: 'perf kvm' tool for monitoring guest performance from host") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
-rw-r--r--tools/perf/util/machine.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 3c520baa198c..28a9541c4835 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1234,8 +1234,9 @@ static char *get_kernel_version(const char *root_dir)
if (!file)
return NULL;
- version[0] = '\0';
tmp = fgets(version, sizeof(version), file);
+ if (!tmp)
+ *version = '\0';
fclose(file);
name = strstr(version, prefix);