summaryrefslogtreecommitdiff
path: root/mdstat.c
diff options
context:
space:
mode:
authorJes Sorensen <Jes.Sorensen@redhat.com>2011-11-03 08:07:21 +1100
committerNeilBrown <neilb@suse.de>2011-11-03 08:07:21 +1100
commitd94a4f62bfa7950741f320cc49475fbc8c7046a0 (patch)
treedb58b4798f469f181e6f93a243fe7a17645d4053 /mdstat.c
parentb36c89351659e1ee3367b32715cf12ef80682b12 (diff)
mdstat_read(): Check return value of dup() before using file descriptor
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'mdstat.c')
-rw-r--r--mdstat.c7
1 files changed, 6 insertions, 1 deletions
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)