summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDonald Yandt <donald.yandt@gmail.com>2019-05-14 13:01:00 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-05-15 21:36:47 +0200
commit30ba5b0e66c872faa416a458d32cc3956ecb548a (patch)
tree646052ffc2fe8738b9b2de1b7307ce02587b99cc /tools
parentperf vendor events intel: Add uncore_upi JSON support (diff)
downloadlinux-30ba5b0e66c872faa416a458d32cc3956ecb548a.tar.xz
linux-30ba5b0e66c872faa416a458d32cc3956ecb548a.zip
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 <donald.yandt@gmail.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Avi Kivity <avi@scylladb.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Yanmin Zhang <yanmin_zhang@linux.intel.com> Fixes: a1645ce12adb ("perf: 'perf kvm' tool for monitoring guest performance from host") Link: http://lkml.kernel.org/r/20190514110100.22019-1-donald.yandt@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-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);