From: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
To: Donald Yandt <donald.yandt@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
linux-kernel@vger.kernel.org,
Yanmin Zhang <yanmin_zhang@linux.intel.com>
Subject: Re: [PATCH v2] tools/perf/util: null-terminate version char array upon error
Date: Tue, 14 May 2019 10:36:03 -0300 [thread overview]
Message-ID: <20190514133603.GH3198@kernel.org> (raw)
In-Reply-To: <20190514110100.22019-1-donald.yandt@gmail.com>
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@gmail.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
next prev parent reply other threads:[~2019-05-14 13:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-14 11:01 [PATCH v2] tools/perf/util: null-terminate version char array upon error Donald Yandt
2019-05-14 13:36 ` Arnaldo Carvalho de Melo [this message]
2019-05-18 8:59 ` [tip:perf/core] perf machine: Null-terminate version char array upon fgets(/proc/version) error tip-bot for Donald Yandt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190514133603.GH3198@kernel.org \
--to=arnaldo.melo@gmail.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=donald.yandt@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=yanmin_zhang@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.