From: Thomas Jarosch <thomas.jarosch@intra2net.com>
To: NeilBrown <neilb@suse.de>
Cc: linux-raid@vger.kernel.org
Subject: [mdadm PATCH 2/2] Fix unterminated buffer after readlink() call
Date: Thu, 13 Oct 2011 11:22:13 +0200 [thread overview]
Message-ID: <201110131122.14099.thomas.jarosch@intra2net.com> (raw)
Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
---
mdopen.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/mdopen.c b/mdopen.c
index 0a17421..555ab84 100644
--- a/mdopen.c
+++ b/mdopen.c
@@ -360,8 +360,12 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
if (lstat(chosen, &stb) == 0) {
char buf[300];
+ ssize_t link_len = readlink(chosen, buf, sizeof(buf)-1);
+ if (link_len >= 0)
+ buf[link_len] = '\0';
+
if ((stb.st_mode & S_IFMT) != S_IFLNK ||
- readlink(chosen, buf, 300) <0 ||
+ link_len < 0 ||
strcmp(buf, devname) != 0) {
fprintf(stderr, Name ": %s exists - ignoring\n",
chosen);
--
1.7.4.4
next reply other threads:[~2011-10-13 9:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-13 9:22 Thomas Jarosch [this message]
2011-10-17 0:19 ` [mdadm PATCH 2/2] Fix unterminated buffer after readlink() call NeilBrown
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=201110131122.14099.thomas.jarosch@intra2net.com \
--to=thomas.jarosch@intra2net.com \
--cc=linux-raid@vger.kernel.org \
--cc=neilb@suse.de \
/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;
as well as URLs for NNTP newsgroup(s).