]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: managemon.c fix coverity issues
authorNigel Croxon <ncroxon@redhat.com>
Wed, 24 Jul 2024 13:04:08 +0000 (09:04 -0400)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Tue, 30 Jul 2024 14:05:47 +0000 (16:05 +0200)
Fixing the following coding errors the coverity tools found:

* Event check_return: Calling "fcntl(fd, 4, fl)" without checking
return value. This library function may fail and return an error code.

* Event check_after_deref: Null-checking "new" suggests that it may
be null, but it has already been dereferenced on all paths leading
to the check.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
managemon.c

index 358459e79435984196eec66661718a9181a0c9d0..add6a79e43b6391f5d0ac6bc41efc1f4f3ed6f30 100644 (file)
@@ -776,10 +776,8 @@ static void manage_new(struct mdstat_ent *mdstat,
 
 error:
        pr_err("failed to monitor %s\n", mdstat->metadata_version);
-       if (new) {
-               new->container = NULL;
-               free_aa(new);
-       }
+       new->container = NULL;
+       free_aa(new);
        if (mdi)
                sysfs_free(mdi);
 }
@@ -870,8 +868,15 @@ void read_sock(struct supertype *container)
                return;
 
        fl = fcntl(fd, F_GETFL, 0);
+       if (fl < 0) {
+               close_fd(&fd);
+               return;
+       }
        fl |= O_NONBLOCK;
-       fcntl(fd, F_SETFL, fl);
+       if (fcntl(fd, F_SETFL, fl) < 0) {
+               close_fd(&fd);
+               return;
+       }
 
        do {
                msg.buf = NULL;