]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
imsm: more serial handling fixups
authorDan Williams <dan.j.williams@intel.com>
Wed, 15 Oct 2008 20:12:17 +0000 (13:12 -0700)
committerDan Williams <dan.j.williams@intel.com>
Wed, 15 Oct 2008 20:12:17 +0000 (13:12 -0700)
zero-initialize the serial buffer to handle cases where the response is
less than MAX_RAID_SERIAL_LEN.

Tested-by: Jacek Danecki <jacek.danecki@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
super-intel.c

index 3249b2ccbd6c59f66646c389709737f98e3be686..eb9a9e9f378cfd3b8e0e6d87cd67c05626c826f5 100644 (file)
@@ -938,17 +938,24 @@ static int imsm_read_serial(int fd, char *devname,
                return rv;
        }
 
-       /* trim whitespace */
+       /* trim leading whitespace */
        rsp_len = scsi_serial[3];
        rsp_buf = (char *) &scsi_serial[4];
        c = rsp_buf;
        while (isspace(*c))
                c++;
+
+       /* truncate len to the end of rsp_buf if necessary */
        if (c + MAX_RAID_SERIAL_LEN > rsp_buf + rsp_len)
                len = rsp_len - (c - rsp_buf);
        else
                len = MAX_RAID_SERIAL_LEN;
+
+       /* initialize the buffer and copy rsp_buf characters */
+       memset(serial, 0, MAX_RAID_SERIAL_LEN);
        memcpy(serial, c, len);
+
+       /* trim trailing whitespace starting with the last character copied */
        c = (char *) &serial[len - 1];
        while (isspace(*c) || *c == '\0')
                *c-- = '\0';