tools/perf/util: null-terminate version char array upon error
PATCH v2 1/1 tools/perf/util: null-terminate version char array upon error
If fgets fails due to any other error besides end-of-file, the version char array may not even be null-terminated.
--- tools/perf/util/machine.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/machine.c +2 -1
@@ -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);
--
2.20.1
Em Tue, May 14, 2019 at 07:01:00AM -0400, Donald Yandt escreveu:
Quoted 1 line
If fgets fails due to any other error besides end-of-file, the version char array may not even be null-terminated.
Thanks, but out of curiosity, was this found just by visual inspection? Some static analysis tool? An actual problem you stumbled when processing some /proc/version in a custom kernel?
Also please consider adding a:
So that we can get this picked up by the stable kernel trees. I'm adding it now.
Thanks!
- Arnaldo
Quoted 22 lines
Signed-off-by Donald Yandt <[email protected]>--- tools/perf/util/machine.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/perf/util/machine.c +2
-2@@ -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); --2.20.1
Signature · 1 line
- Arnaldo
tip-bot for Donald Yandt
merge bot[tip:perf/core] perf machine: Null-terminate version char array upon fgets(/proc/version) error
In reply to Donald Yandtperf machine: Null-terminate version char array upon fgets(/proc/version) error
Commit-ID: 30ba5b0e66c872faa416a458d32cc3956ecb548a Gitweb: https://git.kernel.org/tip/30ba5b0e66c872faa416a458d32cc3956ecb548a Author: Donald Yandt <[email protected]> AuthorDate: Tue, 14 May 2019 07:01:00 -0400 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 15 May 2019 16:36:47 -0300
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.
--- tools/perf/util/machine.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/machine.c +2 -1
@@ -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);