diff options
author | Jes Sorensen <Jes.Sorensen@redhat.com> | 2011-11-01 20:30:12 +0100 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2011-11-02 01:18:53 +0100 |
commit | 96ae5973dda6f6f6487c74b5f3944720a5b9d21f (patch) | |
tree | 07ce91ff563e187d7c0fd8183356067efa825b54 /mdopen.c | |
parent | validate_geometry_imsm_volume(): Avoid NULL pointer dereference (diff) | |
download | mdadm-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.c | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -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; |