From: Jes Sorensen Date: Tue, 1 Nov 2011 19:30:12 +0000 (+0100) Subject: make_parts(): Fix case of comparing against uninitialized variables X-Git-Tag: mdadm-3.2.3~77 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=96ae5973dda6f6f6487c74b5f3944720a5b9d21f;p=thirdparty%2Fmdadm.git make_parts(): Fix case of comparing against uninitialized variables 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 Signed-off-by: NeilBrown --- diff --git a/mdopen.c b/mdopen.c index 555ab84f..eac1c1fc 100644 --- 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;