mdadm/0145-mdadm-mdstat-fix-coverity-issue-CHECKED_RETURN.patch

47 lines
1.1 KiB
Diff
Raw Permalink Normal View History

From 6984814b6fd879efae178acb057c1025aa4c64e8 Mon Sep 17 00:00:00 2001
From: Xiao Ni <xni@redhat.com>
Date: Fri, 26 Jul 2024 15:14:11 +0800
Subject: [PATCH 145/157] 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>
---
mdstat.c | 12 +++++++++---
1 file 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);
--
2.41.0