diff options
author | Thomas Jarosch <thomas.jarosch@intra2net.com> | 2011-10-13 11:22:13 +0200 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2011-10-17 02:15:05 +0200 |
commit | fca13185fc23760503a91e7f881286375e71ce4c (patch) | |
tree | 98761b91b3b2b44b10435437ff6dc3afb5f6b79b /mdopen.c | |
parent | Fix off-by-one in readlink() buffer size handling (diff) | |
download | mdadm-fca13185fc23760503a91e7f881286375e71ce4c.tar.xz mdadm-fca13185fc23760503a91e7f881286375e71ce4c.zip |
Fix unterminated buffer after readlink() call
Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'mdopen.c')
-rw-r--r-- | mdopen.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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); |