]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdmon: fix freeing unallocated memory
authorHans de Goede <hdegoede@redhat.com>
Thu, 24 Sep 2009 13:52:06 +0000 (06:52 -0700)
committerDan Williams <dan.j.williams@intel.com>
Thu, 24 Sep 2009 13:52:06 +0000 (06:52 -0700)
mdmon was creating a supertype struct with malloc, and thus not
necessarily getting zero-d memory.

This was causing it to segfault when called like this from the initrd:
/sbin/mdmon /proc/mdstat /sysroot

The problem was that  load_super_imsm would get called on the non-zero'd
super struct, whcih in turn calls free_super_imsm, which checks st->sb,
which should be zero but isn't and then starts freeing bogus memory.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
mdmon.c

diff --git a/mdmon.c b/mdmon.c
index 37f97af1761721230127ca65ee65a96c6a776301..31994d8c55ec18871f86b7d1b999b4917194cacc 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -395,7 +395,7 @@ int mdmon(char *devname, int devnum, int scan, char *switchroot)
        } else
                pfd[0] = pfd[1] = -1;
 
-       container = malloc(sizeof(*container));
+       container = calloc(1, sizeof(*container));
        container->devnum = devnum;
        container->devname = devname;
        container->arrays = NULL;