]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
FIX: NULL pointer to strdup() can be passed
authorAdam Kwolek <adam.kwolek@intel.com>
Tue, 7 Feb 2012 14:03:03 +0000 (15:03 +0100)
committerNeilBrown <neilb@suse.de>
Thu, 9 Feb 2012 01:20:51 +0000 (12:20 +1100)
When result from strchr() is NULL and it is assigned to subarray,
NULL pointer can be passed to strdup() function and coredump file
is generated.

Subarray is checked for NULL pointer, so it is assumed that it can
be NULL at this moment.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
util.c

diff --git a/util.c b/util.c
index e5f7a202ba66fd02de8a0bbe5b54bd8b3e931f9e..7abbff7517750ca71e3d979c38a3364a9b20793e 100644 (file)
--- a/util.c
+++ b/util.c
@@ -966,9 +966,10 @@ struct supertype *super_by_fd(int fd, char **subarrayp)
                char *dev = verstr+1;
 
                subarray = strchr(dev, '/');
-               if (subarray)
+               if (subarray) {
                        *subarray++ = '\0';
-               subarray = strdup(subarray);
+                       subarray = strdup(subarray);
+               }
                container = devname2devnum(dev);
                if (sra)
                        sysfs_free(sra);