From dffaa31672d5445921c5acd5d09b7c32746b8a9c Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Wed, 19 Nov 2008 11:04:40 +0100 Subject: [PATCH] Valgrind fixes for checkers Declare an array does not zero it out. Hence we might read some random garbage here. Signed-off-by: Hannes Reinecke --- libmultipath/checkers/emc_clariion.c | 29 ++++---- libmultipath/checkers/hp_sw.c | 125 ++++++++++++++++++----------------- libmultipath/checkers/rdac.c | 2 + libmultipath/checkers/tur.c | 1 + 4 files changed, 82 insertions(+), 75 deletions(-) diff --git a/libmultipath/checkers/emc_clariion.c b/libmultipath/checkers/emc_clariion.c index dd546f6..3a88b0b 100644 --- a/libmultipath/checkers/emc_clariion.c +++ b/libmultipath/checkers/emc_clariion.c @@ -103,6 +103,8 @@ int libcheck_check (struct checker * c) int ret; memset(&io_hdr, 0, sizeof (struct sg_io_hdr)); + memset(sense_buffer, 0, 128); + memset(sb, 0, SENSE_BUFF_LEN); io_hdr.interface_id = 'S'; io_hdr.cmd_len = sizeof (inqCmdBlk); io_hdr.mx_sb_len = sizeof (sb); @@ -129,7 +131,7 @@ int libcheck_check (struct checker * c) } if ( /* Effective initiator type */ - sense_buffer[27] != 0x03 + sense_buffer[27] != 0x03 /* * Failover mode should be set to 1 (PNR failover mode) * or 4 (ALUA failover mode). @@ -156,7 +158,7 @@ int libcheck_check (struct checker * c) "or LUNZ"); return PATH_DOWN; } - + /* * store the LUN WWN there and compare that it indeed did not * change in between, to protect against the path suddenly @@ -172,28 +174,29 @@ int libcheck_check (struct checker * c) memcpy(ct->wwn, &sense_buffer[10], 16); ct->wwn_set = 1; } - + /* * Issue read on active path to determine if inactive snapshot. */ if (sense_buffer[4] == 2) {/* if active path */ unsigned char buf[4096]; + memset(buf, 0, 4096); ret = sg_read(c->fd, &buf[0], sbb = &sb[0]); if (ret == PATH_DOWN) { hexadecimal_to_ascii(ct->wwn, wwnstr); /* - * Check for inactive snapshot LU this way. Must + * Check for inactive snapshot LU this way. Must * fail these. - */ + */ if (((sbb[2]&0xf) == 5) && (sbb[12] == 0x25) && (sbb[13]==1)) { /* - * Do this so that we can fail even the - * passive paths which will return + * Do this so that we can fail even the + * passive paths which will return * 02/04/03 not 05/25/01 on read. - */ + */ SET_INACTIVE_SNAP(c); MSG(c, "emc_clariion_checker: Active " "path to inactive snapshot WWN %s.", @@ -207,10 +210,10 @@ int libcheck_check (struct checker * c) MSG(c, "emc_clariion_checker: Active path is " "healthy."); /* - * Remove the path from the set of paths to inactive - * snapshot LUs if it was in this list since the - * snapshot is no longer inactive. - */ + * Remove the path from the set of paths to inactive + * snapshot LUs if it was in this list since the + * snapshot is no longer inactive. + */ CLR_INACTIVE_SNAP(c); } } else { @@ -222,7 +225,7 @@ int libcheck_check (struct checker * c) ret = PATH_DOWN; } else { MSG(c, - "emc_clariion_checker: Passive path is healthy."); + "emc_clariion_checker: Passive path is healthy."); ret = PATH_UP; /* not ghost */ } } diff --git a/libmultipath/checkers/hp_sw.c b/libmultipath/checkers/hp_sw.c index 7509307..3f28d85 100644 --- a/libmultipath/checkers/hp_sw.c +++ b/libmultipath/checkers/hp_sw.c @@ -48,75 +48,76 @@ static int do_inq(int sg_fd, int cmddt, int evpd, unsigned int pg_op, void *resp, int mx_resp_len, int noisy) { - unsigned char inqCmdBlk[INQUIRY_CMDLEN] = - { INQUIRY_CMD, 0, 0, 0, 0, 0 }; - unsigned char sense_b[SENSE_BUFF_LEN]; - struct sg_io_hdr io_hdr; - - if (cmddt) - inqCmdBlk[1] |= 2; - if (evpd) - inqCmdBlk[1] |= 1; - inqCmdBlk[2] = (unsigned char) pg_op; + unsigned char inqCmdBlk[INQUIRY_CMDLEN] = + { INQUIRY_CMD, 0, 0, 0, 0, 0 }; + unsigned char sense_b[SENSE_BUFF_LEN]; + struct sg_io_hdr io_hdr; + + if (cmddt) + inqCmdBlk[1] |= 2; + if (evpd) + inqCmdBlk[1] |= 1; + inqCmdBlk[2] = (unsigned char) pg_op; inqCmdBlk[3] = (unsigned char)((mx_resp_len >> 8) & 0xff); inqCmdBlk[4] = (unsigned char) (mx_resp_len & 0xff); - memset(&io_hdr, 0, sizeof (struct sg_io_hdr)); - io_hdr.interface_id = 'S'; - io_hdr.cmd_len = sizeof (inqCmdBlk); - io_hdr.mx_sb_len = sizeof (sense_b); - io_hdr.dxfer_direction = SG_DXFER_FROM_DEV; - io_hdr.dxfer_len = mx_resp_len; - io_hdr.dxferp = resp; - io_hdr.cmdp = inqCmdBlk; - io_hdr.sbp = sense_b; - io_hdr.timeout = DEF_TIMEOUT; - - if (ioctl(sg_fd, SG_IO, &io_hdr) < 0) - return 1; - - /* treat SG_ERR here to get rid of sg_err.[ch] */ - io_hdr.status &= 0x7e; - if ((0 == io_hdr.status) && (0 == io_hdr.host_status) && - (0 == io_hdr.driver_status)) - return 0; - if ((SCSI_CHECK_CONDITION == io_hdr.status) || - (SCSI_COMMAND_TERMINATED == io_hdr.status) || - (SG_ERR_DRIVER_SENSE == (0xf & io_hdr.driver_status))) { - if (io_hdr.sbp && (io_hdr.sb_len_wr > 2)) { - int sense_key; - unsigned char * sense_buffer = io_hdr.sbp; - if (sense_buffer[0] & 0x2) - sense_key = sense_buffer[1] & 0xf; - else - sense_key = sense_buffer[2] & 0xf; - if(RECOVERED_ERROR == sense_key) - return 0; - } - } - return 1; + memset(&io_hdr, 0, sizeof (struct sg_io_hdr)); + memset(sense_b, 0, SENSE_BUFF_LEN); + io_hdr.interface_id = 'S'; + io_hdr.cmd_len = sizeof (inqCmdBlk); + io_hdr.mx_sb_len = sizeof (sense_b); + io_hdr.dxfer_direction = SG_DXFER_FROM_DEV; + io_hdr.dxfer_len = mx_resp_len; + io_hdr.dxferp = resp; + io_hdr.cmdp = inqCmdBlk; + io_hdr.sbp = sense_b; + io_hdr.timeout = DEF_TIMEOUT; + + if (ioctl(sg_fd, SG_IO, &io_hdr) < 0) + return 1; + + /* treat SG_ERR here to get rid of sg_err.[ch] */ + io_hdr.status &= 0x7e; + if ((0 == io_hdr.status) && (0 == io_hdr.host_status) && + (0 == io_hdr.driver_status)) + return 0; + if ((SCSI_CHECK_CONDITION == io_hdr.status) || + (SCSI_COMMAND_TERMINATED == io_hdr.status) || + (SG_ERR_DRIVER_SENSE == (0xf & io_hdr.driver_status))) { + if (io_hdr.sbp && (io_hdr.sb_len_wr > 2)) { + int sense_key; + unsigned char * sense_buffer = io_hdr.sbp; + if (sense_buffer[0] & 0x2) + sense_key = sense_buffer[1] & 0xf; + else + sense_key = sense_buffer[2] & 0xf; + if(RECOVERED_ERROR == sense_key) + return 0; + } + } + return 1; } static int do_tur (int fd) { - unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 }; - struct sg_io_hdr io_hdr; - unsigned char sense_buffer[32]; - - memset(&io_hdr, 0, sizeof (struct sg_io_hdr)); - io_hdr.interface_id = 'S'; - io_hdr.cmd_len = sizeof (turCmdBlk); - io_hdr.mx_sb_len = sizeof (sense_buffer); - io_hdr.dxfer_direction = SG_DXFER_NONE; - io_hdr.cmdp = turCmdBlk; - io_hdr.sbp = sense_buffer; - io_hdr.timeout = DEF_TIMEOUT; - io_hdr.pack_id = 0; - - if (ioctl(fd, SG_IO, &io_hdr) < 0) + unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 }; + struct sg_io_hdr io_hdr; + unsigned char sense_buffer[32]; + + memset(&io_hdr, 0, sizeof (struct sg_io_hdr)); + io_hdr.interface_id = 'S'; + io_hdr.cmd_len = sizeof (turCmdBlk); + io_hdr.mx_sb_len = sizeof (sense_buffer); + io_hdr.dxfer_direction = SG_DXFER_NONE; + io_hdr.cmdp = turCmdBlk; + io_hdr.sbp = sense_buffer; + io_hdr.timeout = DEF_TIMEOUT; + io_hdr.pack_id = 0; + + if (ioctl(fd, SG_IO, &io_hdr) < 0) return 1; - if (io_hdr.info & SG_INFO_OK_MASK) + if (io_hdr.info & SG_INFO_OK_MASK) return 1; return 0; @@ -134,8 +135,8 @@ libcheck_check (struct checker * c) if (do_tur(c->fd)) { MSG(c, MSG_HP_SW_GHOST); - return PATH_GHOST; - } + return PATH_GHOST; + } MSG(c, MSG_HP_SW_UP); return PATH_UP; } diff --git a/libmultipath/checkers/rdac.c b/libmultipath/checkers/rdac.c index 0086125..c4c7b8f 100644 --- a/libmultipath/checkers/rdac.c +++ b/libmultipath/checkers/rdac.c @@ -52,6 +52,7 @@ do_inq(int sg_fd, unsigned int pg_op, void *resp, int mx_resp_len) inqCmdBlk[2] = (unsigned char) pg_op; inqCmdBlk[4] = (unsigned char) (mx_resp_len & 0xff); memset(&io_hdr, 0, sizeof (struct sg_io_hdr)); + memset(sense_b, 0, SENSE_BUFF_LEN); io_hdr.interface_id = 'S'; io_hdr.cmd_len = sizeof (inqCmdBlk); @@ -100,6 +101,7 @@ libcheck_check (struct checker * c) { struct volume_access_inq inq; + memset(&inq, 0, sizeof(struct volume_access_inq)); if (0 != do_inq(c->fd, 0xC9, &inq, sizeof(struct volume_access_inq))) { MSG(c, MSG_RDAC_DOWN); return PATH_DOWN; diff --git a/libmultipath/checkers/tur.c b/libmultipath/checkers/tur.c index 43b846d..820a2e3 100644 --- a/libmultipath/checkers/tur.c +++ b/libmultipath/checkers/tur.c @@ -47,6 +47,7 @@ libcheck_check (struct checker * c) retry: memset(&io_hdr, 0, sizeof (struct sg_io_hdr)); + memset(&sense_buffer, 0, 32); io_hdr.interface_id = 'S'; io_hdr.cmd_len = sizeof (turCmdBlk); io_hdr.mx_sb_len = sizeof (sense_buffer); -- 2.7.4