Valgrind fixes for checkers
authorHannes Reinecke <hare@suse.de>
Wed, 19 Nov 2008 10:04:40 +0000 (11:04 +0100)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Tue, 21 Apr 2009 22:18:06 +0000 (00:18 +0200)
Declare an array does not zero it out. Hence we might read some
random garbage here.

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/checkers/emc_clariion.c
libmultipath/checkers/hp_sw.c
libmultipath/checkers/rdac.c
libmultipath/checkers/tur.c

index dd546f63cdeb19d23c927a12d7b077f5f26457cb..3a88b0b4fdb5596c2ea8ae10dfd57fe1c2645098 100644 (file)
@@ -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 */
                }
        }
index 7509307fa13843f1fa5fc6231ffaa23d58f36cf3..3f28d85bf750eacae53503750af60379427f31f3 100644 (file)
@@ -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;
 }
index 00861250358f29b34e9210034673cf411c41dcda..c4c7b8f462fc5265001491d20f0fbedd5a9b568b 100644 (file)
@@ -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;
index 43b846de4e46787c00c6631686c6c9f022c4cd5b..820a2e36ee7820532c853cbc667a074cf24f714a 100644 (file)
@@ -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);