summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXiao Ni <xni@redhat.com>2024-07-26 09:14:11 +0200
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2024-08-05 11:13:17 +0200
commit6984814b6fd879efae178acb057c1025aa4c64e8 (patch)
treee2992b715f7674e1ce2e0371a73ced3e331096cf
parentmdadm/mdopen: fix coverity issue STRING_OVERFLOW (diff)
downloadmdadm-6984814b6fd879efae178acb057c1025aa4c64e8.tar.xz
mdadm-6984814b6fd879efae178acb057c1025aa4c64e8.zip
mdadm/mdstat: fix coverity issue CHECKED_RETURN
It needs to check return values when functions return value. Signed-off-by: Xiao Ni <xni@redhat.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
-rw-r--r--mdstat.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/mdstat.c b/mdstat.c
index cbbace3d..a971a957 100644
--- a/mdstat.c
+++ b/mdstat.c
@@ -194,8 +194,11 @@ struct mdstat_ent *mdstat_read(int hold, int start)
f = fopen("/proc/mdstat", "r");
if (f == NULL)
return NULL;
- else
- fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
+
+ if (fcntl(fileno(f), F_SETFD, FD_CLOEXEC) < 0) {
+ fclose(f);
+ return NULL;
+ }
all = NULL;
end = &all;
@@ -329,7 +332,10 @@ struct mdstat_ent *mdstat_read(int hold, int start)
}
if (hold && mdstat_fd == -1) {
mdstat_fd = dup(fileno(f));
- fcntl(mdstat_fd, F_SETFD, FD_CLOEXEC);
+ if (fcntl(mdstat_fd, F_SETFD, FD_CLOEXEC) < 0) {
+ fclose(f);
+ return NULL;
+ }
}
fclose(f);