From: Dan Williams Date: Wed, 15 Oct 2008 20:12:17 +0000 (-0700) Subject: imsm: more serial handling fixups X-Git-Tag: mdadm-3.0-devel2~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c3db629a6e29839f82657131d8aa1d045f1fd3e;p=thirdparty%2Fmdadm.git imsm: more serial handling fixups zero-initialize the serial buffer to handle cases where the response is less than MAX_RAID_SERIAL_LEN. Tested-by: Jacek Danecki Signed-off-by: Dan Williams --- diff --git a/super-intel.c b/super-intel.c index 3249b2cc..eb9a9e9f 100644 --- a/super-intel.c +++ b/super-intel.c @@ -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';