]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Fix possible NULL dereference in super_by_fd
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 514b7139252120b50e5f4d80bcaa246290c1d023..1ad6fd0dc3b5d266b17b0cd92c093a2de17439eb 100644 (file)
--- a/util.c
+++ b/util.c
@@ -757,7 +757,8 @@ struct supertype *super_by_fd(int fd)
 
        if (sra)
                sysfs_free(sra);
-       st->sb = NULL;
+       if (st)
+               st->sb = NULL;
        return st;
 }
 
@@ -884,11 +885,14 @@ int find_free_devnum(int use_partitions)
        for (devnum = 127; devnum != 128;
             devnum = devnum ? devnum-1 : (1<<22)-1) {
                char *dn;
-               if (mddev_busy(use_partitions ? (-1-devnum) : devnum))
+               int _devnum;
+
+               _devnum = use_partitions ? (-1-devnum) : devnum;
+               if (mddev_busy(_devnum))
                        continue;
                /* make sure it is new to /dev too, at least as a
                 * non-standard */
-               dn = map_dev(dev2major(devnum), dev2minor(devnum), 0);
+               dn = map_dev(dev2major(_devnum), dev2minor(_devnum), 0);
                if (dn && ! is_standard(dn, NULL))
                        continue;
                break;