From c1b5aac873bc551f352a2f30026ce8d178773350 Mon Sep 17 00:00:00 2001 From: Donald Yandt Date: Wed, 12 Jun 2019 22:39:23 +0800 Subject: [PATCH] perf machine: Null-terminate version char array upon fgets(/proc/version) error mainline inclusion from mainline-5.2-rc1 commit 30ba5b0e66c8 category: bugfix bugzilla: 16430 CVE: NA ------------------------------------------------- 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 Cc: Alexander Shishkin Cc: Avi Kivity Cc: Jiri Olsa Cc: Peter Zijlstra Cc: Yanmin Zhang 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 Signed-off-by: Wei Li Reviewed-by: Jian Cheng Signed-off-by: Yang Yingliang --- tools/perf/util/machine.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 076718a7b3ea..94971708ff71 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1171,8 +1171,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); -- GitLab