]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
make_parts(): Fix case of comparing against uninitialized variables
authorJes Sorensen <Jes.Sorensen@redhat.com>
Tue, 1 Nov 2011 19:30:12 +0000 (20:30 +0100)
committerNeilBrown <neilb@suse.de>
Wed, 2 Nov 2011 00:18:53 +0000 (11:18 +1100)
Silencing gcc's warning of uninitialized variables was hiding a bug
where if we have /dev/md64 as a symlink, and /dev/md64p1 was a real
device node.

In this case major_num and minor_num would not get populated, but we
end up comparing against them because the stat for md64p1 succeeds.

Instead of using the int foo = foo trick, change the code to set
set the variables to invalid values so comparisons will fail.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
mdopen.c

index 555ab84f6d4de832cdbf3b2d0355887ddd196288..eac1c1fcb904edb426b2e7862f26df41a9106311 100644 (file)
--- a/mdopen.c
+++ b/mdopen.c
@@ -38,9 +38,9 @@ void make_parts(char *dev, int cnt)
         * else that of dev
         */
        struct stat stb;
-       int major_num = major_num; /* quiet gcc -Os unitialized warning */
-       int minor_num = minor_num; /* quiet gcc -Os unitialized warning */
-       int odig = odig; /* quiet gcc -Os unitialized warning */
+       int major_num;
+       int minor_num;
+       int odig;
        int i;
        int nlen = strlen(dev) + 20;
        char *name;
@@ -53,23 +53,26 @@ void make_parts(char *dev, int cnt)
        if (lstat(dev, &stb)!= 0)
                return;
 
-       if (S_ISLNK(stb.st_mode)) {
+       if (S_ISBLK(stb.st_mode)) {
+               major_num = major(stb.st_rdev);
+               minor_num = minor(stb.st_rdev);
+               odig = -1;
+       } else if (S_ISLNK(stb.st_mode)) {
                int len = readlink(dev, orig, sizeof(orig));
                if (len < 0 || len > 1000)
                        return;
                orig[len] = 0;
                odig = isdigit(orig[len-1]);
-       } else if (S_ISBLK(stb.st_mode)) {
-               major_num = major(stb.st_rdev);
-               minor_num = minor(stb.st_rdev);
+               major_num = -1;
+               minor_num = -1;
        } else
-                  return;
+               return;
        name = malloc(nlen);
        for (i=1; i <= cnt ; i++) {
                struct stat stb2;
                snprintf(name, nlen, "%s%s%d", dev, dig?"p":"", i);
                if (stat(name, &stb2)==0) {
-                       if (!S_ISBLK(stb2.st_mode))
+                       if (!S_ISBLK(stb2.st_mode) || !S_ISBLK(stb.st_mode))
                                continue;
                        if (stb2.st_rdev == makedev(major_num, minor_num+i))
                                continue;