[PATCH 03/12] mdstat_read(): Check return value of dup() before using file descriptor

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

 



From: Jes Sorensen <Jes.Sorensen@xxxxxxxxxx>

Signed-off-by: Jes Sorensen <Jes.Sorensen@xxxxxxxxxx>
---
 mdstat.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/mdstat.c b/mdstat.c
index abf6bf9..6ead24c 100644
--- a/mdstat.c
+++ b/mdstat.c
@@ -131,10 +131,15 @@ struct mdstat_ent *mdstat_read(int hold, int start)
 	FILE *f;
 	struct mdstat_ent *all, *rv, **end, **insert_here;
 	char *line;
+	int fd;
 
 	if (hold && mdstat_fd != -1) {
 		lseek(mdstat_fd, 0L, 0);
-		f = fdopen(dup(mdstat_fd), "r");
+		fd = dup(mdstat_fd);
+		if (fd >= 0)
+			f = fdopen(fd, "r");
+		else
+			return NULL;
 	} else
 		f = fopen("/proc/mdstat", "r");
 	if (f == NULL)
-- 
1.7.6.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