From: Donald Yandt <donald.yandt@gmail.com>
To: peterz@infradead.org
Cc: mingo@redhat.com, acme@kernel.org,
alexander.shishkin@linux.intel.com, jolsa@redhat.com,
linux-kernel@vger.kernel.org,
Donald Yandt <donald.yandt@gmail.com>
Subject: [PATCH v2] tools/perf/util: null-terminate version char array upon error
Date: Tue, 14 May 2019 07:01:00 -0400 [thread overview]
Message-ID: <20190514110100.22019-1-donald.yandt@gmail.com> (raw)
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>
---
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
next reply other threads:[~2019-05-14 11:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-14 11:01 Donald Yandt [this message]
2019-05-14 13:36 ` Arnaldo Carvalho de Melo
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=20190514110100.22019-1-donald.yandt@gmail.com \
--to=donald.yandt@gmail.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
/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
all inboxes | Powered by JetHome®