]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdstat_read(): Check return value of dup() before using file descriptor
authorJes Sorensen <Jes.Sorensen@redhat.com>
Wed, 2 Nov 2011 21:07:21 +0000 (08:07 +1100)
committerNeilBrown <neilb@suse.de>
Wed, 2 Nov 2011 21:07:21 +0000 (08:07 +1100)
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
mdstat.c

index abf6bf953c309013bd3750bf9a58763d48fbe051..6ead24c4a7a1d52682655e243f0a0bf803cd7bf0 100644 (file)
--- 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)