Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Donald Yandt and committed by
Arnaldo Carvalho de Melo
30ba5b0e bf6d18cf

+2 -1
+2 -1
tools/perf/util/machine.c
··· 1234 1234 if (!file) 1235 1235 return NULL; 1236 1236 1237 - version[0] = '\0'; 1238 1237 tmp = fgets(version, sizeof(version), file); 1238 + if (!tmp) 1239 + *version = '\0'; 1239 1240 fclose(file); 1240 1241 1241 1242 name = strstr(version, prefix);