From d94a4f62bfa7950741f320cc49475fbc8c7046a0 Mon Sep 17 00:00:00 2001 From: Jes Sorensen Date: Thu, 3 Nov 2011 08:07:21 +1100 Subject: [PATCH] mdstat_read(): Check return value of dup() before using file descriptor Signed-off-by: Jes Sorensen Signed-off-by: NeilBrown --- mdstat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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) -- 2.47.2