Thread (15 messages) 15 messages, 2 authors, 2011-11-03
STALE5345d

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

From: <hidden>
Date: 2011-11-02 14:42:08
Subsystem: the rest · Maintainer: Linus Torvalds

From: Jes Sorensen <redacted>

Signed-off-by: Jes Sorensen <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help