summaryrefslogtreecommitdiffstats
path: root/mdopen.c
diff options
context:
space:
mode:
authorJes Sorensen <Jes.Sorensen@redhat.com>2011-11-01 20:30:12 +0100
committerNeilBrown <neilb@suse.de>2011-11-02 01:18:53 +0100
commit96ae5973dda6f6f6487c74b5f3944720a5b9d21f (patch)
tree07ce91ff563e187d7c0fd8183356067efa825b54 /mdopen.c
parentvalidate_geometry_imsm_volume(): Avoid NULL pointer dereference (diff)
downloadmdadm-96ae5973dda6f6f6487c74b5f3944720a5b9d21f.tar.xz
mdadm-96ae5973dda6f6f6487c74b5f3944720a5b9d21f.zip
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 <Jes.Sorensen@redhat.com> Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'mdopen.c')
-rw-r--r--mdopen.c21
1 files changed, 12 insertions, 9 deletions
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;