From: tip-bot for Donald Yandt <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: alexander.shishkin@linux.intel.com, mingo@kernel.org,
linux-kernel@vger.kernel.org, peterz@infradead.org,
hpa@zytor.com, yanmin_zhang@linux.intel.com, acme@redhat.com,
jolsa@redhat.com, tglx@linutronix.de, donald.yandt@gmail.com,
avi@scylladb.com
Subject: [tip:perf/core] perf machine: Null-terminate version char array upon fgets(/proc/version) error
Date: Sat, 18 May 2019 01:59:26 -0700 [thread overview]
Message-ID: <tip-30ba5b0e66c872faa416a458d32cc3956ecb548a@git.kernel.org> (raw)
In-Reply-To: <20190514110100.22019-1-donald.yandt@gmail.com>
Commit-ID: 30ba5b0e66c872faa416a458d32cc3956ecb548a
Gitweb: https://git.kernel.org/tip/30ba5b0e66c872faa416a458d32cc3956ecb548a
Author: Donald Yandt <donald.yandt@gmail.com>
AuthorDate: Tue, 14 May 2019 07:01:00 -0400
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
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.
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>
---
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 3c520baa198c..28a9541c4835 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);
prev parent reply other threads:[~2019-05-18 8:59 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
2019-05-18 8:59 ` tip-bot for Donald Yandt [this message]
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=tip-30ba5b0e66c872faa416a458d32cc3956ecb548a@git.kernel.org \
--to=tipbot@zytor.com \
--cc=acme@redhat.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=avi@scylladb.com \
--cc=donald.yandt@gmail.com \
--cc=hpa@zytor.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox