From: Jes Sorensen Date: Wed, 2 Nov 2011 21:07:21 +0000 (+1100) Subject: mdstat_read(): Check return value of dup() before using file descriptor X-Git-Tag: mdadm-3.2.3~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d94a4f62bfa7950741f320cc49475fbc8c7046a0;p=thirdparty%2Fmdadm.git mdstat_read(): Check return value of dup() before using file descriptor Signed-off-by: Jes Sorensen Signed-off-by: NeilBrown --- diff --git a/mdstat.c b/mdstat.c index abf6bf95..6ead24c4 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)