[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190514133603.GH3198@kernel.org>
Date: Tue, 14 May 2019 10:36:03 -0300
From: Arnaldo Carvalho de Melo <arnaldo.melo@...il.com>
To: Donald Yandt <donald.yandt@...il.com>
Cc: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>, linux-kernel@...r.kernel.org,
Yanmin Zhang <yanmin_zhang@...ux.intel.com>
Subject: Re: [PATCH v2] tools/perf/util: null-terminate version char array
upon error
Em Tue, May 14, 2019 at 07:01:00AM -0400, Donald Yandt escreveu:
> 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:
Fixes: a1645ce12adb ("perf: 'perf kvm' tool for monitoring guest performance from host")
So that we can get this picked up by the stable kernel trees. I'm adding
it now.
Thanks!
- Arnaldo
> Signed-off-by: Donald Yandt <donald.yandt@...il.com>
> ---
> 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 3c520baa1..28a9541c4 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);
> --
> 2.20.1
--
- Arnaldo
Powered by blists - more mailing lists