提交 c1b5aac8 编写于 作者: D Donald Yandt 提交者: Xie XiuQi

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: NDonald 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: a1645ce1 ("perf: 'perf kvm' tool for monitoring guest performance from host")
Link: http://lkml.kernel.org/r/20190514110100.22019-1-donald.yandt@gmail.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: NWei Li <liwei391@huawei.com>
Reviewed-by: NJian Cheng <cj.chengjian@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 737c7d19
...@@ -1171,8 +1171,9 @@ static char *get_kernel_version(const char *root_dir) ...@@ -1171,8 +1171,9 @@ static char *get_kernel_version(const char *root_dir)
if (!file) if (!file)
return NULL; return NULL;
version[0] = '\0';
tmp = fgets(version, sizeof(version), file); tmp = fgets(version, sizeof(version), file);
if (!tmp)
*version = '\0';
fclose(file); fclose(file);
name = strstr(version, prefix); name = strstr(version, prefix);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册