diff options
author | Donald Yandt <donald.yandt@gmail.com> | 2019-05-14 07:01:00 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-05-15 16:36:47 -0300 |
commit | 30ba5b0e66c872faa416a458d32cc3956ecb548a (patch) | |
tree | 646052ffc2fe8738b9b2de1b7307ce02587b99cc | |
parent | bf6d18cffa5f26bd5dc71485c2a2ad0c42a0ce60 (diff) | |
download | linux-stable-30ba5b0e66c872faa416a458d32cc3956ecb548a.tar.gz linux-stable-30ba5b0e66c872faa416a458d32cc3956ecb548a.tar.bz2 linux-stable-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>
-rw-r--r-- | tools/perf/util/machine.c | 3 |
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); |