From fca13185fc23760503a91e7f881286375e71ce4c Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Thu, 13 Oct 2011 11:22:13 +0200 Subject: Fix unterminated buffer after readlink() call Signed-off-by: Thomas Jarosch Signed-off-by: NeilBrown --- mdopen.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'mdopen.c') diff --git a/mdopen.c b/mdopen.c index 0a174211..555ab84f 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); -- cgit v1.2.3