[mdadm PATCH 2/2] Fix unterminated buffer after readlink() call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
---
 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
--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux