]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm/Incremental: fix coverity issues.
authorXiao Ni <xni@redhat.com>
Fri, 26 Jul 2024 07:14:06 +0000 (15:14 +0800)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Mon, 5 Aug 2024 09:07:59 +0000 (11:07 +0200)
There are two issues PW.PARAMETER_HIDDEN (declaration hides
parameter 'devname') and INTEGER_OVERFLOW.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Incremental.c

index abc7721b51dc5bc88c10b12b9f691a94efc80b36..fc4e68ffb3c9ab015cf0a38e8fb89650c30fea98 100644 (file)
@@ -770,7 +770,7 @@ static int count_active(struct supertype *st, struct mdinfo *sra,
                        replcnt++;
                st->ss->free_super(st);
        }
-       if (max_journal_events >= max_events - 1)
+       if (max_events > 0 && max_journal_events >= max_events - 1)
                bestinfo->journal_clean = 1;
 
        if (!avail)
@@ -1113,7 +1113,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                int fd = -1;
                struct mdinfo info;
                struct supertype *st2 = NULL;
-               char *devname = NULL;
+               char *dev_path_name = NULL;
                unsigned long long devsectors;
                char *pathlist[2];
 
@@ -1142,14 +1142,14 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                domain_free(domlist);
                domlist = NULL;
 
-               if (asprintf(&devname, "/dev/disk/by-path/%s", de->d_name) != 1) {
-                       devname = NULL;
+               if (asprintf(&dev_path_name, "/dev/disk/by-path/%s", de->d_name) != 1) {
+                       dev_path_name = NULL;
                        goto next;
                }
-               fd = open(devname, O_RDONLY);
+               fd = open(dev_path_name, O_RDONLY);
                if (fd < 0)
                        goto next;
-               if (get_dev_size(fd, devname, &devsectors) == 0)
+               if (get_dev_size(fd, dev_path_name, &devsectors) == 0)
                        goto next;
                devsectors >>= 9;
 
@@ -1188,8 +1188,8 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                if (chosen == NULL || chosen_size < info.component_size) {
                        chosen_size = info.component_size;
                        free(chosen);
-                       chosen = devname;
-                       devname = NULL;
+                       chosen = dev_path_name;
+                       dev_path_name = NULL;
                        if (chosen_st) {
                                chosen_st->ss->free_super(chosen_st);
                                free(chosen_st);
@@ -1199,7 +1199,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                }
 
        next:
-               free(devname);
+               free(dev_path_name);
                domain_free(domlist);
                dev_policy_free(pol2);
                if (st2)
@@ -1246,7 +1246,7 @@ static int is_bare(int dfd)
 
        /* OK, first 4K appear blank, try the end. */
        get_dev_size(dfd, NULL, &size);
-       if (lseek(dfd, size-4096, SEEK_SET) < 0 ||
+       if ((size >= 4096 && lseek(dfd, size-4096, SEEK_SET) < 0) ||
            read(dfd, buf, 4096) != 4096)
                return 0;