Blame SOURCES/BZ_1633235-sg3_utils-1.44-covscan-fix.patch

60e6aa
From 7a39d7758c9c799bc6341a8a339a91692ec8a9dd Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Tue, 25 Sep 2018 18:52:26 +0800
60e6aa
Subject: [PATCH 01/30] Fix overrunning array.
60e6aa
60e6aa
Issue:
60e6aa
 * `jrp` might pointing outside of join_arr after the for loop.
60e6aa
 * Out of index: `op->cdb`.
60e6aa
60e6aa
Fix:
60e6aa
 * Check index number before dereferencing `jpr` pointer.
60e6aa
 * Check index number before access `op->cdb` array.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_raw.c | 2 +-
60e6aa
 src/sg_ses.c | 2 +-
60e6aa
 2 files changed, 2 insertions(+), 2 deletions(-)
60e6aa
60e6aa
diff --git a/src/sg_raw.c b/src/sg_raw.c
60e6aa
index 92c2287..90c3d9c 100644
60e6aa
--- a/src/sg_raw.c
60e6aa
+++ b/src/sg_raw.c
60e6aa
@@ -454,7 +454,7 @@ parse_cmd_line(struct opts_t * op, int argc, char *argv[])
60e6aa
             return SG_LIB_SYNTAX_ERROR;
60e6aa
         }
60e6aa
 
60e6aa
-        if (op->cdb_length > MAX_SCSI_CDBSZ) {
60e6aa
+        if (op->cdb_length >= MAX_SCSI_CDBSZ) {
60e6aa
             pr2serr("CDB too long (max. %d bytes)\n", MAX_SCSI_CDBSZ);
60e6aa
             return SG_LIB_SYNTAX_ERROR;
60e6aa
         }
60e6aa
diff --git a/src/sg_ses.c b/src/sg_ses.c
60e6aa
index abb1fea..29b66b3 100644
60e6aa
--- a/src/sg_ses.c
60e6aa
+++ b/src/sg_ses.c
60e6aa
@@ -5310,7 +5310,7 @@ ses_cgs(struct sg_pt_base * ptvp, const struct tuple_acronym_val * tavp,
60e6aa
         if (op->ind_indiv_last <= op->ind_indiv)
60e6aa
             break;
60e6aa
     }   /* end of loop over join array */
60e6aa
-    if ((NULL == jrp->enc_statp) || (k >= MX_JOIN_ROWS)) {
60e6aa
+    if ((k >= MX_JOIN_ROWS) || (NULL == jrp->enc_statp)) {
60e6aa
         if (op->desc_name)
60e6aa
             pr2serr("descriptor name: %s not found (check the 'ed' page "
60e6aa
                     "[0x7])\n", op->desc_name);
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From ad7d26c94ad555a647528c31eb11b78fc0ac4474 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Tue, 25 Sep 2018 18:59:01 +0800
60e6aa
Subject: [PATCH 02/30] sg_persist: Workaround for false warning of covscan.
60e6aa
60e6aa
The covscan think we might access out of index on `tid_arr` but
60e6aa
actually we did the index check before.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_persist.c | 2 +-
60e6aa
 1 file changed, 1 insertion(+), 1 deletion(-)
60e6aa
60e6aa
diff --git a/src/sg_persist.c b/src/sg_persist.c
60e6aa
index f582d32..b565a5a 100644
60e6aa
--- a/src/sg_persist.c
60e6aa
+++ b/src/sg_persist.c
60e6aa
@@ -824,7 +824,7 @@ decode_file_tids(const char * fnp, struct opts_t * op)
60e6aa
                     pr2serr("%s: array length exceeded\n", __func__);
60e6aa
                     goto bad;
60e6aa
                 }
60e6aa
-                tid_arr[off + k] = h;
60e6aa
+                op->transportid_arr[off + k] = h;
60e6aa
                 lcp = strpbrk(lcp, " ,\t");
60e6aa
                 if (NULL == lcp)
60e6aa
                     break;
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 24e54cf4c04fa7aa3bdf8e7315ce6240ab306c5f Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Tue, 25 Sep 2018 19:12:34 +0800
60e6aa
Subject: [PATCH 03/30] sg_opcodes: Fix overrun of array.
60e6aa
60e6aa
Overrunning array `b` as 4 + m might bigger than the size of array `b`.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_opcodes.c | 3 ++-
60e6aa
 1 file changed, 2 insertions(+), 1 deletion(-)
60e6aa
60e6aa
diff --git a/src/sg_opcodes.c b/src/sg_opcodes.c
60e6aa
index 21897c4..a8cf762 100644
60e6aa
--- a/src/sg_opcodes.c
60e6aa
+++ b/src/sg_opcodes.c
60e6aa
@@ -799,7 +799,8 @@ list_all_codes(uint8_t * rsoc_buff, int rsoc_len, struct opts_t * op,
60e6aa
                         printf("             usage: ");
60e6aa
                     else
60e6aa
                         printf("        cdb usage: ");
60e6aa
-                    for (m = 0; m < cdb_sz; ++m)
60e6aa
+                    for (m = 0; (m < cdb_sz) && ((size_t) (4 + m) < sizeof(b));
60e6aa
+                         ++m)
60e6aa
                         printf("%.2x ", b[4 + m]);
60e6aa
                     printf("\n");
60e6aa
                 }
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From ca241cf82c746391edb3b460550310da40202fe4 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 20:34:42 +0800
60e6aa
Subject: [PATCH 04/30] sg_lib: Fix overruning of array
60e6aa
 `sg_lib_scsi_status_sense_arr`
60e6aa
60e6aa
Check index before dereferencing `mp`.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 include/sg_lib_data.h | 2 ++
60e6aa
 lib/sg_lib.c          | 3 +++
60e6aa
 lib/sg_lib_data.c     | 6 ++++++
60e6aa
 3 files changed, 11 insertions(+)
60e6aa
60e6aa
diff --git a/include/sg_lib_data.h b/include/sg_lib_data.h
60e6aa
index a870043..9739453 100644
60e6aa
--- a/include/sg_lib_data.h
60e6aa
+++ b/include/sg_lib_data.h
60e6aa
@@ -122,6 +122,8 @@ extern struct sg_lib_simple_value_name_t sg_lib_nvme_nvm_cmd_arr[];
60e6aa
 extern struct sg_lib_value_name_t sg_lib_nvme_cmd_status_arr[];
60e6aa
 extern struct sg_lib_4tuple_u8 sg_lib_scsi_status_sense_arr[];
60e6aa
 
60e6aa
+size_t sg_lib_scsi_status_sense_arr_len(void);
60e6aa
+
60e6aa
 extern struct sg_value_2names_t sg_exit_str_arr[];
60e6aa
 
60e6aa
 #ifdef __cplusplus
60e6aa
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
60e6aa
index c2c5891..c281cce 100644
60e6aa
--- a/lib/sg_lib.c
60e6aa
+++ b/lib/sg_lib.c
60e6aa
@@ -2585,6 +2585,9 @@ sg_nvme_status2scsi(uint16_t sct_sc, uint8_t * status_p, uint8_t * sk_p,
60e6aa
         return false;
60e6aa
     } else if (ind >= k)
60e6aa
         return false;
60e6aa
+    /* Check whether `ind` is out of index of sg_lib_scsi_status_sense_arr */
60e6aa
+    if (ind >= (int) sg_lib_scsi_status_sense_arr_len())
60e6aa
+        return false;
60e6aa
     mp = sg_lib_scsi_status_sense_arr + ind;
60e6aa
     if (status_p)
60e6aa
         *status_p = mp->t1;
60e6aa
diff --git a/lib/sg_lib_data.c b/lib/sg_lib_data.c
60e6aa
index d5ca380..3a898e5 100644
60e6aa
--- a/lib/sg_lib_data.c
60e6aa
+++ b/lib/sg_lib_data.c
60e6aa
@@ -1850,3 +1850,9 @@ struct sg_value_2names_t sg_exit_str_arr[] = {
60e6aa
 };
60e6aa
 
60e6aa
 #endif           /* (SG_SCSI_STRINGS && HAVE_NVME && (! IGNORE_NVME)) */
60e6aa
+
60e6aa
+size_t sg_lib_scsi_status_sense_arr_len(void)
60e6aa
+{
60e6aa
+    return sizeof(sg_lib_scsi_status_sense_arr)/
60e6aa
+        sizeof(struct sg_lib_4tuple_u8) - 1;
60e6aa
+}
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 36a487285d9e7c9afce9acaefa8fad25017cacd8 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Fri, 28 Sep 2018 20:56:26 +0800
60e6aa
Subject: [PATCH 05/30] sginfo,sg_dd: Fix resource leak.
60e6aa
60e6aa
 * sginfo: Free the memory of `headsp`.
60e6aa
 * sg_dd: Close infd/outfd before return error.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_dd.c  | 6 ++++++
60e6aa
 src/sginfo.c | 1 +
60e6aa
 2 files changed, 7 insertions(+)
60e6aa
60e6aa
diff --git a/src/sg_dd.c b/src/sg_dd.c
60e6aa
index edd8f9c..6bdbcdb 100644
60e6aa
--- a/src/sg_dd.c
60e6aa
+++ b/src/sg_dd.c
60e6aa
@@ -1276,6 +1276,7 @@ open_if(const char * inf, int64_t skip, int bpt, struct flags_t * ifp,
60e6aa
                 perror(ME "SG_SET_RESERVED_SIZE error");
60e6aa
             res = ioctl(infd, SG_GET_VERSION_NUM, &t);
60e6aa
             if ((res < 0) || (t < 30000)) {
60e6aa
+                close(infd);
60e6aa
                 if (FT_BLOCK & *in_typep)
60e6aa
                     pr2serr(ME "SG_IO unsupported on this block device\n");
60e6aa
                 else
60e6aa
@@ -1308,6 +1309,7 @@ open_if(const char * inf, int64_t skip, int bpt, struct flags_t * ifp,
60e6aa
                     snprintf(ebuff, EBUFF_SZ, ME "couldn't skip to "
60e6aa
                              "required position on %s", inf);
60e6aa
                     perror(ebuff);
60e6aa
+                    close(infd);
60e6aa
                     goto file_err;
60e6aa
                 }
60e6aa
                 if (vb)
60e6aa
@@ -1341,6 +1343,7 @@ open_if(const char * inf, int64_t skip, int bpt, struct flags_t * ifp,
60e6aa
 file_err:
60e6aa
     return -SG_LIB_FILE_ERROR;
60e6aa
 other_err:
60e6aa
+    close(infd);
60e6aa
     return -SG_LIB_CAT_OTHER;
60e6aa
 }
60e6aa
 
60e6aa
@@ -1398,6 +1401,7 @@ open_of(const char * outf, int64_t seek, int bpt, struct flags_t * ofp,
60e6aa
                 perror(ME "SG_SET_RESERVED_SIZE error");
60e6aa
             res = ioctl(outfd, SG_GET_VERSION_NUM, &t);
60e6aa
             if ((res < 0) || (t < 30000)) {
60e6aa
+                close(outfd);
60e6aa
                 pr2serr(ME "sg driver prior to 3.x.y\n");
60e6aa
                 goto file_err;
60e6aa
             }
60e6aa
@@ -1447,6 +1451,7 @@ open_of(const char * outf, int64_t seek, int bpt, struct flags_t * ofp,
60e6aa
                 snprintf(ebuff, EBUFF_SZ,
60e6aa
                     ME "couldn't seek to required position on %s", outf);
60e6aa
                 perror(ebuff);
60e6aa
+                close(outfd);
60e6aa
                 goto file_err;
60e6aa
             }
60e6aa
             if (vb)
60e6aa
@@ -1469,6 +1474,7 @@ open_of(const char * outf, int64_t seek, int bpt, struct flags_t * ofp,
60e6aa
 file_err:
60e6aa
     return -SG_LIB_FILE_ERROR;
60e6aa
 other_err:
60e6aa
+    close(outfd);
60e6aa
     return -SG_LIB_CAT_OTHER;
60e6aa
 }
60e6aa
 
60e6aa
diff --git a/src/sginfo.c b/src/sginfo.c
60e6aa
index bddc964..1032f05 100644
60e6aa
--- a/src/sginfo.c
60e6aa
+++ b/src/sginfo.c
60e6aa
@@ -1825,6 +1825,7 @@ trytenbyte:
60e6aa
         }
60e6aa
     }
60e6aa
     printf("\n");
60e6aa
+    free(headsp);
60e6aa
     return status;
60e6aa
 }
60e6aa
 
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 5bd764553056b2182db8ef8d6c1a1ab09b0d5a24 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 21:10:23 +0800
60e6aa
Subject: [PATCH 06/30] covscan: Calling func without checking return value
60e6aa
60e6aa
* Use the macro `_ignore_return()` defined in `misc.h` to ignore the
60e6aa
  return value of functions.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/misc.h          | 34 ++++++++++++++++++++++++++++++++++
60e6aa
 src/sg_get_config.c |  6 ++++--
60e6aa
 src/sg_logs.c       |  6 ++++--
60e6aa
 src/sg_persist.c    | 13 +++++++++----
60e6aa
 src/sg_xcopy.c      | 23 +++++++++++++----------
60e6aa
 5 files changed, 64 insertions(+), 18 deletions(-)
60e6aa
 create mode 100644 src/misc.h
60e6aa
60e6aa
diff --git a/src/misc.h b/src/misc.h
60e6aa
new file mode 100644
60e6aa
index 0000000..6289eae
60e6aa
--- /dev/null
60e6aa
+++ b/src/misc.h
60e6aa
@@ -0,0 +1,34 @@
60e6aa
+/*
60e6aa
+ * Copyright (c) 2018 Red Hat, Inc.
60e6aa
+ * All rights reserved.
60e6aa
+ *
60e6aa
+ * Redistribution and use in source and binary forms, with or without
60e6aa
+ * modification, are permitted provided that the following conditions
60e6aa
+ * are met:
60e6aa
+ * 1. Redistributions of source code must retain the above copyright
60e6aa
+ *    notice, this list of conditions and the following disclaimer.
60e6aa
+ * 2. Redistributions in binary form must reproduce the above copyright
60e6aa
+ *    notice, this list of conditions and the following disclaimer in the
60e6aa
+ *    documentation and/or other materials provided with the distribution.
60e6aa
+ *
60e6aa
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
60e6aa
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60e6aa
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60e6aa
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
60e6aa
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60e6aa
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60e6aa
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60e6aa
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60e6aa
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60e6aa
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60e6aa
+ * SUCH DAMAGE.
60e6aa
+ *
60e6aa
+ * Author:  Gris Ge <fge@redhat.com>
60e6aa
+ */
60e6aa
+#ifndef __SG_UTILS_MISC_H__
60e6aa
+#define __SG_UTILS_MISC_H__
60e6aa
+
60e6aa
+/* Just make coverity scan happy. */
60e6aa
+#define _ignore_return(x) if (x) {}
60e6aa
+
60e6aa
+#endif /* End of __SG_UTILS_MISC_H__ */
60e6aa
diff --git a/src/sg_get_config.c b/src/sg_get_config.c
60e6aa
index 28af720..4d2cc9b 100644
60e6aa
--- a/src/sg_get_config.c
60e6aa
+++ b/src/sg_get_config.c
60e6aa
@@ -24,6 +24,8 @@
60e6aa
 #include "sg_unaligned.h"
60e6aa
 #include "sg_pr2serr.h"
60e6aa
 
60e6aa
+#include "misc.h"
60e6aa
+
60e6aa
 /* A utility program originally written for the Linux OS SCSI subsystem.
60e6aa
  *
60e6aa
  * This program outputs information provided by a SCSI "Get Configuration"
60e6aa
@@ -1091,7 +1093,7 @@ main(int argc, char * argv[])
60e6aa
         pr2serr(ME "%s doesn't respond to a SCSI INQUIRY\n", device_name);
60e6aa
         return SG_LIB_CAT_OTHER;
60e6aa
     }
60e6aa
-    sg_cmds_close_device(sg_fd);
60e6aa
+    _ignore_return(sg_cmds_close_device(sg_fd));
60e6aa
 
60e6aa
     sg_fd = sg_cmds_open_device(device_name, readonly, verbose);
60e6aa
     if (sg_fd < 0) {
60e6aa
@@ -1122,7 +1124,7 @@ main(int argc, char * argv[])
60e6aa
     } else {
60e6aa
         char b[80];
60e6aa
 
60e6aa
-        sg_get_category_sense_str(res, sizeof(b), b, verbose);
60e6aa
+        _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, verbose));
60e6aa
         pr2serr("Get Configuration command: %s\n", b);
60e6aa
         if (0 == verbose)
60e6aa
             pr2serr("    try '-v' option for more information\n");
60e6aa
diff --git a/src/sg_logs.c b/src/sg_logs.c
60e6aa
index 61443ff..e4f265e 100644
60e6aa
--- a/src/sg_logs.c
60e6aa
+++ b/src/sg_logs.c
60e6aa
@@ -34,6 +34,8 @@
60e6aa
 #include "sg_unaligned.h"
60e6aa
 #include "sg_pr2serr.h"
60e6aa
 
60e6aa
+#include "misc.h"
60e6aa
+
60e6aa
 static const char * version_str = "1.69 20180911";    /* spc5r19 + sbc4r11 */
60e6aa
 
60e6aa
 #define MX_ALLOC_LEN (0xfffc)
60e6aa
@@ -6776,7 +6778,7 @@ fetchTemperature(int sg_fd, uint8_t * resp, int max_len, struct opts_t * op)
60e6aa
             pr2serr("Unable to find temperature in either Temperature or "
60e6aa
                     "IE log page\n");
60e6aa
     }
60e6aa
-    sg_cmds_close_device(sg_fd);
60e6aa
+    _ignore_return(sg_cmds_close_device(sg_fd));
60e6aa
     return (res >= 0) ? res : SG_LIB_CAT_OTHER;
60e6aa
 }
60e6aa
 
60e6aa
@@ -7246,7 +7248,7 @@ err_out:
60e6aa
     if (free_parr)
60e6aa
         free(free_parr);
60e6aa
     if (sg_fd >= 0)
60e6aa
-        sg_cmds_close_device(sg_fd);
60e6aa
+        _ignore_return(sg_cmds_close_device(sg_fd));
60e6aa
     if (0 == vb) {
60e6aa
         if (! sg_if_can2stderr("sg_logs failed: ", ret))
60e6aa
             pr2serr("Some error occurred, try again with '-v' or '-vv' for "
60e6aa
diff --git a/src/sg_persist.c b/src/sg_persist.c
60e6aa
index b565a5a..2e10aff 100644
60e6aa
--- a/src/sg_persist.c
60e6aa
+++ b/src/sg_persist.c
60e6aa
@@ -33,6 +33,8 @@
60e6aa
 #include "sg_unaligned.h"
60e6aa
 #include "sg_pr2serr.h"
60e6aa
 
60e6aa
+#include "misc.h"
60e6aa
+
60e6aa
 static const char * version_str = "0.66 20180615";
60e6aa
 
60e6aa
 
60e6aa
@@ -303,7 +305,8 @@ prin_work(int sg_fd, const struct opts_t * op)
60e6aa
             pr2serr("PR in (%s): bad field in cdb or parameter list (perhaps "
60e6aa
                     "unsupported service action)\n", b);
60e6aa
         else {
60e6aa
-            sg_get_category_sense_str(res, sizeof(bb), bb, op->verbose);
60e6aa
+            _ignore_return(sg_get_category_sense_str(res, sizeof(bb), bb,
60e6aa
+                                                     op->verbose));
60e6aa
             pr2serr("PR in (%s): %s\n", b, bb);
60e6aa
         }
60e6aa
         goto fini;
60e6aa
@@ -519,7 +522,8 @@ prout_work(int sg_fd, struct opts_t * op)
60e6aa
                 pr2serr("PR out (%s): bad field in cdb or parameter list "
60e6aa
                         "(perhaps unsupported service action)\n", b);
60e6aa
             else {
60e6aa
-                sg_get_category_sense_str(res, sizeof(bb), bb, op->verbose);
60e6aa
+                _ignore_return(sg_get_category_sense_str(res, sizeof(bb), bb,
60e6aa
+                                                         op->verbose));
60e6aa
                 pr2serr("PR out (%s): %s\n", b, bb);
60e6aa
             }
60e6aa
             goto fini;
60e6aa
@@ -573,7 +577,8 @@ prout_reg_move_work(int sg_fd, struct opts_t * op)
60e6aa
         else {
60e6aa
             char bb[80];
60e6aa
 
60e6aa
-            sg_get_category_sense_str(res, sizeof(bb), bb, op->verbose);
60e6aa
+            _ignore_return(sg_get_category_sense_str(res, sizeof(bb), bb,
60e6aa
+                                                     op->verbose));
60e6aa
             pr2serr("PR out (register and move): %s\n", bb);
60e6aa
         }
60e6aa
         goto fini;
60e6aa
@@ -1277,7 +1282,7 @@ main(int argc, char * argv[])
60e6aa
             flagged = true;
60e6aa
             goto fini;
60e6aa
         }
60e6aa
-        sg_cmds_close_device(sg_fd);
60e6aa
+        _ignore_return(sg_cmds_close_device(sg_fd));
60e6aa
     }
60e6aa
 
60e6aa
     if (! op->readwrite_force) {
60e6aa
diff --git a/src/sg_xcopy.c b/src/sg_xcopy.c
60e6aa
index 5facfc8..6230685 100644
60e6aa
--- a/src/sg_xcopy.c
60e6aa
+++ b/src/sg_xcopy.c
60e6aa
@@ -67,6 +67,8 @@
60e6aa
 #include "sg_unaligned.h"
60e6aa
 #include "sg_pr2serr.h"
60e6aa
 
60e6aa
+#include "misc.h"
60e6aa
+
60e6aa
 static const char * version_str = "0.68 20180811";
60e6aa
 
60e6aa
 #define ME "sg_xcopy: "
60e6aa
@@ -341,7 +343,7 @@ open_sg(struct xcopy_fp_t * fp, int vb)
60e6aa
     }
60e6aa
     if (sg_simple_inquiry(fp->sg_fd, &sir, false, vb)) {
60e6aa
         pr2serr("INQUIRY failed on %s\n", ebuff);
60e6aa
-        sg_cmds_close_device(fp->sg_fd);
60e6aa
+        _ignore_return(sg_cmds_close_device(fp->sg_fd));
60e6aa
         fp->sg_fd = -1;
60e6aa
         return -1;
60e6aa
     }
60e6aa
@@ -415,7 +417,7 @@ dd_filetype_str(int ft, char * buff)
60e6aa
     if (FT_OTHER & ft)
60e6aa
         off += sg_scnpr(buff + off, 32, "other (perhaps ordinary file) ");
60e6aa
     if (FT_ERROR & ft)
60e6aa
-        sg_scnpr(buff + off, 32, "unable to 'stat' file ");
60e6aa
+        _ignore_return(sg_scnpr(buff + off, 32, "unable to 'stat' file "));
60e6aa
     return buff;
60e6aa
 }
60e6aa
 
60e6aa
@@ -640,7 +642,7 @@ scsi_extended_copy(int sg_fd, uint8_t list_id,
60e6aa
                                 DEF_GROUP_NUM, DEF_3PC_OUT_TIMEOUT,
60e6aa
                                 xcopyBuff, desc_offset, true, verb);
60e6aa
     if (res) {
60e6aa
-        sg_get_category_sense_str(res, sizeof(b), b, verb);
60e6aa
+        _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, verb));
60e6aa
         pr2serr("Xcopy(LID1): %s\n", b);
60e6aa
     }
60e6aa
     return res;
60e6aa
@@ -660,7 +662,7 @@ scsi_read_capacity(struct xcopy_fp_t *xfp)
60e6aa
     res = sg_ll_readcap_10(xfp->sg_fd, false /* pmi */, 0, rcBuff,
60e6aa
                            READ_CAP_REPLY_LEN, true, verb);
60e6aa
     if (0 != res) {
60e6aa
-        sg_get_category_sense_str(res, sizeof(b), b, verb);
60e6aa
+        _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, verb));
60e6aa
         pr2serr("Read capacity(10): %s\n", b);
60e6aa
         return res;
60e6aa
     }
60e6aa
@@ -672,7 +674,7 @@ scsi_read_capacity(struct xcopy_fp_t *xfp)
60e6aa
         res = sg_ll_readcap_16(xfp->sg_fd, false /* pmi */, 0, rcBuff,
60e6aa
                                RCAP16_REPLY_LEN, true, verb);
60e6aa
         if (0 != res) {
60e6aa
-            sg_get_category_sense_str(res, sizeof(b), b, verb);
60e6aa
+            _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, verb));
60e6aa
             pr2serr("Read capacity(16): %s\n", b);
60e6aa
             return res;
60e6aa
         }
60e6aa
@@ -714,7 +716,7 @@ scsi_operating_parameter(struct xcopy_fp_t *xfp, int is_target)
60e6aa
     res = sg_ll_receive_copy_results(xfp->sg_fd, SA_COPY_OP_PARAMS, 0, rcBuff,
60e6aa
                                      rcBuffLen, true, verb);
60e6aa
     if (0 != res) {
60e6aa
-        sg_get_category_sense_str(res, sizeof(b), b, verb);
60e6aa
+        _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, verb));
60e6aa
         pr2serr("Xcopy operating parameters: %s\n", b);
60e6aa
         return -res;
60e6aa
     }
60e6aa
@@ -1006,8 +1008,8 @@ decode_designation_descriptor(const uint8_t * bp, int i_len)
60e6aa
 {
60e6aa
     char c[2048];
60e6aa
 
60e6aa
-    sg_get_designation_descriptor_str(NULL, bp, i_len, 1, verbose,
60e6aa
-                                      sizeof(c), c);
60e6aa
+    _ignore_return(sg_get_designation_descriptor_str(NULL, bp, i_len, 1,
60e6aa
+                                                     verbose, sizeof(c), c));
60e6aa
     pr2serr("%s", c);
60e6aa
 }
60e6aa
 
60e6aa
@@ -1029,7 +1031,8 @@ desc_from_vpd_id(int sg_fd, uint8_t *desc, int desc_len,
60e6aa
         if (SG_LIB_CAT_ILLEGAL_REQ == res)
60e6aa
             pr2serr("Device identification VPD page not found\n");
60e6aa
         else {
60e6aa
-            sg_get_category_sense_str(res, sizeof(b), b, verbose);
60e6aa
+            _ignore_return(sg_get_category_sense_str(res, sizeof(b), b,
60e6aa
+                                                     verbose));
60e6aa
             pr2serr("VPD inquiry (Device ID): %s\n", b);
60e6aa
             pr2serr("   try again with '-vv'\n");
60e6aa
         }
60e6aa
@@ -1042,7 +1045,7 @@ desc_from_vpd_id(int sg_fd, uint8_t *desc, int desc_len,
60e6aa
     res = sg_ll_inquiry(sg_fd, false, true, VPD_DEVICE_ID, rcBuff, len, true,
60e6aa
                         verb);
60e6aa
     if (0 != res) {
60e6aa
-        sg_get_category_sense_str(res, sizeof(b), b, verbose);
60e6aa
+        _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, verbose));
60e6aa
         pr2serr("VPD inquiry (Device ID): %s\n", b);
60e6aa
         return res;
60e6aa
     } else if (rcBuff[1] != VPD_DEVICE_ID) {
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 3a99f93d11cea7d4273477c698eb6bfb2f6d4696 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 22:14:11 +0800
60e6aa
Subject: [PATCH 07/30] sg_dd: flock does not allows negative fd.
60e6aa
60e6aa
 * The `outfd` could be -1 in line 1408. We do negative number check on
60e6aa
   `outfd` before sending to flock.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_dd.c | 2 +-
60e6aa
 1 file changed, 1 insertion(+), 1 deletion(-)
60e6aa
60e6aa
diff --git a/src/sg_dd.c b/src/sg_dd.c
60e6aa
index 6bdbcdb..8696ee7 100644
60e6aa
--- a/src/sg_dd.c
60e6aa
+++ b/src/sg_dd.c
60e6aa
@@ -1459,7 +1459,7 @@ open_of(const char * outf, int64_t seek, int bpt, struct flags_t * ofp,
60e6aa
                         "\n", (uint64_t)offset);
60e6aa
         }
60e6aa
     }
60e6aa
-    if (ofp->flock) {
60e6aa
+    if ((ofp->flock) && (outfd >= 0)) {
60e6aa
         res = flock(outfd, LOCK_EX | LOCK_NB);
60e6aa
         if (res < 0) {
60e6aa
             close(outfd);
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 158f6547f156b8a7fc175904b4bd502642ed56a5 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 22:21:00 +0800
60e6aa
Subject: [PATCH 08/30] sginfo: Suspend the fallthrough warning.
60e6aa
60e6aa
* The GCC and Clang will complain about fallthrough of switch statement,
60e6aa
  use maker comments to suspend that.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sginfo.c | 3 +++
60e6aa
 1 file changed, 3 insertions(+)
60e6aa
60e6aa
diff --git a/src/sginfo.c b/src/sginfo.c
60e6aa
index 1032f05..9c626ee 100644
60e6aa
--- a/src/sginfo.c
60e6aa
+++ b/src/sginfo.c
60e6aa
@@ -1757,6 +1757,7 @@ trytenbyte:
60e6aa
                     }
60e6aa
                     else if (!sorthead) printf("|");
60e6aa
                 }
60e6aa
+                /* fall through */
60e6aa
             case 5:     /* physical sector */
60e6aa
                 while (len > 0) {
60e6aa
                     snprintf((char *)cbuffer1, 40, "%6d:%2u:%5d",
60e6aa
@@ -1775,6 +1776,7 @@ trytenbyte:
60e6aa
                     }
60e6aa
                     else if (!sorthead) printf("|");
60e6aa
                 }
60e6aa
+                /* fall through */
60e6aa
             case 0:     /* lba (32 bit) */
60e6aa
                 while (len > 0) {
60e6aa
                     printf("%10d", getnbyte(df, 4));
60e6aa
@@ -1788,6 +1790,7 @@ trytenbyte:
60e6aa
                     else
60e6aa
                         printf("|");
60e6aa
                 }
60e6aa
+                /* fall through */
60e6aa
             case 3:     /* lba (64 bit) */
60e6aa
                 while (len > 0) {
60e6aa
                     printf("%15" PRId64 , getnbyte_ll(df, 8));
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 7e90f135eeb3900735847df32ed878d8207c59dc Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 22:24:01 +0800
60e6aa
Subject: [PATCH 09/30] sg_get_lba_status: Fix incorrect use of
60e6aa
 sg_ll_get_lba_status32.
60e6aa
60e6aa
Fix the incorrect argument order of `sg_get_lba_status()`.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_get_lba_status.c | 2 +-
60e6aa
 1 file changed, 1 insertion(+), 1 deletion(-)
60e6aa
60e6aa
diff --git a/src/sg_get_lba_status.c b/src/sg_get_lba_status.c
60e6aa
index 91c7a96..61a823b 100644
60e6aa
--- a/src/sg_get_lba_status.c
60e6aa
+++ b/src/sg_get_lba_status.c
60e6aa
@@ -340,7 +340,7 @@ main(int argc, char * argv[])
60e6aa
         res = sg_ll_get_lba_status16(sg_fd, lba, rt, glbasBuffp, maxlen, true,
60e6aa
                                      verbose);
60e6aa
     else if (do_32)     /* keep analyser happy since do_32 must be true */
60e6aa
-        res = sg_ll_get_lba_status32(sg_fd, lba, element_id, scan_len, rt,
60e6aa
+        res = sg_ll_get_lba_status32(sg_fd, lba, scan_len, element_id, rt,
60e6aa
                                      glbasBuffp, maxlen, true, verbose);
60e6aa
 
60e6aa
     ret = res;
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From c86a7be69c8601722ba39ef6eacc6aaa993b3d5a Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 22:35:35 +0800
60e6aa
Subject: [PATCH 10/30] rescan-scsi-bus.sh: Fix shellcheck warning of SC2155.
60e6aa
60e6aa
Declare and assign separately to avoid masking return values:
60e6aa
    https://github.com/koalaman/shellcheck/wiki/SC2155
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 scripts/rescan-scsi-bus.sh | 24 ++++++++++++++++--------
60e6aa
 1 file changed, 16 insertions(+), 8 deletions(-)
60e6aa
60e6aa
diff --git a/scripts/rescan-scsi-bus.sh b/scripts/rescan-scsi-bus.sh
60e6aa
index 6989208..75e169a 100755
60e6aa
--- a/scripts/rescan-scsi-bus.sh
60e6aa
+++ b/scripts/rescan-scsi-bus.sh
60e6aa
@@ -314,8 +314,10 @@ testonline ()
60e6aa
       fi
60e6aa
   else
60e6aa
       # Ignore disk revision change
60e6aa
-      local old_str_no_rev=`echo "$TMPSTR" | sed -e 's/.\{4\}$//'`
60e6aa
-      local new_str_no_rev=`echo "$STR" | sed -e 's/.\{4\}$//'`
60e6aa
+      local old_str_no_rev
60e6aa
+      old_str_no_rev=`echo "$TMPSTR" | sed -e 's/.\{4\}$//'`
60e6aa
+      local new_str_no_rev
60e6aa
+      new_str_no_rev=`echo "$STR" | sed -e 's/.\{4\}$//'`
60e6aa
       if [ "$old_str_no_rev" != "$new_str_no_rev" ]; then
60e6aa
         echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nfrom:${SCSISTR#* } \nto: $STR ${norm} \n\n\n"
60e6aa
         return 1
60e6aa
@@ -696,7 +698,8 @@ searchexisting()
60e6aa
   local tmpch;
60e6aa
   local tmpid
60e6aa
   local match=0
60e6aa
-  local targets=`ls -d /sys/class/scsi_device/$host:* 2> /dev/null | egrep -o $host:[0-9]+:[0-9]+ | sort | uniq`
60e6aa
+  local targets
60e6aa
+  targets=`ls -d /sys/class/scsi_device/$host:* 2> /dev/null | egrep -o $host:[0-9]+:[0-9]+ | sort | uniq`
60e6aa
 
60e6aa
   # Nothing came back on this host, so we should skip it
60e6aa
   test -z "$targets" && return
60e6aa
@@ -742,13 +745,15 @@ searchexisting()
60e6aa
 findremapped()
60e6aa
 {
60e6aa
   local hctl=;
60e6aa
-  local devs=`ls /sys/class/scsi_device/`
60e6aa
+  local devs
60e6aa
+  devs=`ls /sys/class/scsi_device/`
60e6aa
   local sddev=
60e6aa
   local id_serial=
60e6aa
   local id_serial_old=
60e6aa
   local remapped=
60e6aa
   mpaths=""
60e6aa
-  local tmpfile=$(mktemp /tmp/rescan-scsi-bus.XXXXXXXX 2> /dev/null)
60e6aa
+  local tmpfile
60e6aa
+  tmpfile=$(mktemp /tmp/rescan-scsi-bus.XXXXXXXX 2> /dev/null)
60e6aa
 
60e6aa
   if [ -z "$tmpfile" ] ; then
60e6aa
     tmpfile="/tmp/rescan-scsi-bus.$$"
60e6aa
@@ -835,7 +840,8 @@ incrchgd()
60e6aa
   fi
60e6aa
 
60e6aa
   if test -n "$mp_enable" ; then
60e6aa
-    local sdev="`findsddev \"$hctl\"`"
60e6aa
+    local sdev
60e6aa
+    sdev="`findsddev \"$hctl\"`"
60e6aa
     if test -n "$sdev" ; then
60e6aa
       findmultipath "$sdev"
60e6aa
     fi
60e6aa
@@ -853,7 +859,8 @@ incrrmvd()
60e6aa
   fi
60e6aa
 
60e6aa
   if test -n "$mp_enable" ; then
60e6aa
-    local sdev="`findsddev \"$hctl\"`"
60e6aa
+    local sdev
60e6aa
+    sdev="`findsddev \"$hctl\"`"
60e6aa
     if test -n "$sdev" ; then
60e6aa
       findmultipath "$sdev"
60e6aa
     fi
60e6aa
@@ -902,7 +909,8 @@ findmultipath()
60e6aa
     return 1
60e6aa
   fi
60e6aa
 
60e6aa
-  local maj_min=`cat /sys/block/$dev/dev`
60e6aa
+  local maj_min
60e6aa
+  maj_min=`cat /sys/block/$dev/dev`
60e6aa
   for mp in $($DMSETUP ls --target=multipath | cut -f 1) ; do
60e6aa
     [ "$mp" = "No" ] && break;
60e6aa
     if $DMSETUP status $mp | grep -q " $maj_min "; then
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 0185fcb6527b331082eb10ef733a2a2f746578d8 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 22:36:44 +0800
60e6aa
Subject: [PATCH 11/30] rescan-scsi-bus.sh: Fix incorrect use of `break`.
60e6aa
60e6aa
Should use `return` instead in `if` code block.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 scripts/rescan-scsi-bus.sh | 2 +-
60e6aa
 1 file changed, 1 insertion(+), 1 deletion(-)
60e6aa
60e6aa
diff --git a/scripts/rescan-scsi-bus.sh b/scripts/rescan-scsi-bus.sh
60e6aa
index 75e169a..37f121d 100755
60e6aa
--- a/scripts/rescan-scsi-bus.sh
60e6aa
+++ b/scripts/rescan-scsi-bus.sh
60e6aa
@@ -548,7 +548,7 @@ dolunscan()
60e6aa
       printf "\r\e[A";
60e6aa
       # Optimization: if lun==0, stop here (only if in non-remove mode)
60e6aa
       if test $lun = 0 -a -z "$remove" -a $optscan = 1; then 
60e6aa
-        break;
60e6aa
+        return;
60e6aa
       fi
60e6aa
     else 
60e6aa
       if test "$remappedlun0" != "2" ; then
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 533e455337251971a94b5d9bce2183fb55383db6 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 22:39:13 +0800
60e6aa
Subject: [PATCH 12/30] rescan-scsi-bus.sh: Use dummy for throwaway variable.
60e6aa
60e6aa
* The `offset` is unused and should be replaced by dummy `_`.
60e6aa
    https://github.com/koalaman/shellcheck/wiki/SC2034
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 scripts/rescan-scsi-bus.sh | 2 +-
60e6aa
 1 file changed, 1 insertion(+), 1 deletion(-)
60e6aa
60e6aa
diff --git a/scripts/rescan-scsi-bus.sh b/scripts/rescan-scsi-bus.sh
60e6aa
index 37f121d..ed3cf49 100755
60e6aa
--- a/scripts/rescan-scsi-bus.sh
60e6aa
+++ b/scripts/rescan-scsi-bus.sh
60e6aa
@@ -235,7 +235,7 @@ is_removable ()
60e6aa
   p=/sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device/inquiry
60e6aa
   # Extract the second byte of the INQUIRY response and check bit 7 (mask 0x80).
60e6aa
   b=$(od -tx1 -j1 -N1 "$p" 2>/dev/null |
60e6aa
-           { read -r offset byte rest; echo -n "$byte"; })
60e6aa
+           { read -r _ byte rest; echo -n "$byte"; })
60e6aa
   if [ -n "$b" ]; then
60e6aa
     echo $(((0x$b & 0x80) != 0))
60e6aa
   else
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 751afef7a7a5049a6d1a6171efb65e9e2f515911 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 22:55:08 +0800
60e6aa
Subject: [PATCH 13/30] sg_write_x: parameter string might overflow a char
60e6aa
 array.
60e6aa
60e6aa
 * The `lcp` might overflow the char array `c`. Use `snprintf` instead.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_write_x.c | 6 ++++--
60e6aa
 1 file changed, 4 insertions(+), 2 deletions(-)
60e6aa
60e6aa
diff --git a/src/sg_write_x.c b/src/sg_write_x.c
60e6aa
index 3b8f091..89b5616 100644
60e6aa
--- a/src/sg_write_x.c
60e6aa
+++ b/src/sg_write_x.c
60e6aa
@@ -671,8 +671,10 @@ parse_scat_pi_line(const char * lcp, uint8_t * up, uint32_t * sum_num)
60e6aa
     if (cp) {   /* copy from first non whitespace ... */
60e6aa
         memcpy(c, lcp, cp - lcp);  /* ... to just prior to first '#' */
60e6aa
         c[cp - lcp] = '\0';
60e6aa
-    } else
60e6aa
-        strcpy(c, lcp);         /* ... to end of line, including null */
60e6aa
+    } else {
60e6aa
+        /* ... to end of line, including null */
60e6aa
+        snprintf(c, sizeof(c)/sizeof(char), "%s", lcp);
60e6aa
+    }
60e6aa
     ll = sg_get_llnum(bp);
60e6aa
     ok = ((-1 != ll) || all_ascii_f_s(bp, 16));
60e6aa
     if (! ok) {
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From cd7fdbdeffabd41fe9e9c65e1158cbdb6f906f20 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 22:56:48 +0800
60e6aa
Subject: [PATCH 14/30] sg_vpd_vendor: Fix potential string overflow.
60e6aa
60e6aa
Currently, none of `vendor_vpd_pg` name string is longer than 64,
60e6aa
to ease the coverity scan, change strcpy to snprintf.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_vpd_vendor.c | 2 +-
60e6aa
 1 file changed, 1 insertion(+), 1 deletion(-)
60e6aa
60e6aa
diff --git a/src/sg_vpd_vendor.c b/src/sg_vpd_vendor.c
60e6aa
index 3c75177..9a73748 100644
60e6aa
--- a/src/sg_vpd_vendor.c
60e6aa
+++ b/src/sg_vpd_vendor.c
60e6aa
@@ -1420,7 +1420,7 @@ svpd_decode_vendor(int sg_fd, struct opts_t * op, int off)
60e6aa
     if (0 == res) {
60e6aa
         vnp = svpd_get_v_detail(op->vpd_pn, op->vend_prod_num, 0xf & rp[0]);
60e6aa
         if (vnp && vnp->name)
60e6aa
-            strcpy(name, vnp->name);
60e6aa
+            snprintf(name, sizeof(name)/sizeof(char), "%s", vnp->name);
60e6aa
         else
60e6aa
             snprintf(name, sizeof(name) - 1, "Vendor VPD page=0x%x",
60e6aa
                      op->vpd_pn);
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 7ddd2de9d7c7ebcfcb3c33da9993cb60a91b0525 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 23:38:05 +0800
60e6aa
Subject: [PATCH 15/30] sg_write_x: Remove dead code.
60e6aa
60e6aa
* The `k` is always smaller than 3, `default:` will never be reached.
60e6aa
* The `ok` is already checked for non-zero.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_write_x.c | 10 +---------
60e6aa
 1 file changed, 1 insertion(+), 9 deletions(-)
60e6aa
60e6aa
diff --git a/src/sg_write_x.c b/src/sg_write_x.c
60e6aa
index 89b5616..d6949ed 100644
60e6aa
--- a/src/sg_write_x.c
60e6aa
+++ b/src/sg_write_x.c
60e6aa
@@ -750,10 +750,6 @@ parse_scat_pi_line(const char * lcp, uint8_t * up, uint32_t * sum_num)
60e6aa
             } else if (up)
60e6aa
                 sg_put_unaligned_be16((uint16_t)ll, up + 18);
60e6aa
             break;
60e6aa
-        default:
60e6aa
-            pr2serr("%s: k=%d should not be >= 3\n", __func__, k);
60e6aa
-            ok = false;
60e6aa
-            break;
60e6aa
         }
60e6aa
         if (! ok)
60e6aa
             break;
60e6aa
@@ -774,13 +770,9 @@ parse_scat_pi_line(const char * lcp, uint8_t * up, uint32_t * sum_num)
60e6aa
             if (up)
60e6aa
                 sg_put_unaligned_be16((uint16_t)DEF_TM, up + 18);
60e6aa
             break;
60e6aa
-        default:
60e6aa
-            pr2serr("%s: k=%d should not be >= 3\n", __func__, k);
60e6aa
-            ok = false;
60e6aa
-            break;
60e6aa
         }
60e6aa
     }
60e6aa
-    return ok ? 0 : SG_LIB_SYNTAX_ERROR;
60e6aa
+    return 0;
60e6aa
 }
60e6aa
 
60e6aa
 /* Read pairs or quintets from a scat_file and places them in a T10 scatter
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 2ff6254d584b2c673b9d6289da2f6af6e293a3d3 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 23:36:58 +0800
60e6aa
Subject: [PATCH 16/30] sg_vpd: Remove dead code.
60e6aa
60e6aa
 * The `n` is between 0 and 7, the `default` statement is never reached.
60e6aa
60e6aa
 * The `do_hex` will never been bigger than 2 at that line.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_vpd.c | 7 -------
60e6aa
 1 file changed, 7 deletions(-)
60e6aa
60e6aa
diff --git a/src/sg_vpd.c b/src/sg_vpd.c
60e6aa
index a15ed74..081232d 100644
60e6aa
--- a/src/sg_vpd.c
60e6aa
+++ b/src/sg_vpd.c
60e6aa
@@ -1233,9 +1233,6 @@ decode_x_inq_vpd(uint8_t * b, int len, int do_hex, bool do_long,
60e6aa
             case 7:
60e6aa
                 printf(" [protection types 1, 2 and 3 supported]\n");
60e6aa
                 break;
60e6aa
-            default:
60e6aa
-                printf("\n");
60e6aa
-                break;
60e6aa
             }
60e6aa
         } else
60e6aa
             printf("\n");
60e6aa
@@ -1991,8 +1988,6 @@ decode_proto_lu_vpd(uint8_t * buff, int len, int do_hex)
60e6aa
             continue;
60e6aa
         if (2 == do_hex)
60e6aa
             hex2stdout(bp + 8, desc_len, 1);
60e6aa
-        else if (do_hex > 2)
60e6aa
-            hex2stdout(bp, bump, 1);
60e6aa
         else {
60e6aa
             switch (proto) {
60e6aa
             case TPROTO_SAS:
60e6aa
@@ -2042,8 +2037,6 @@ decode_proto_port_vpd(uint8_t * buff, int len, int do_hex)
60e6aa
             continue;
60e6aa
         if (2 == do_hex)
60e6aa
             hex2stdout(bp + 8, desc_len, 1);
60e6aa
-        else if (do_hex > 2)
60e6aa
-            hex2stdout(bp, bump, 1);
60e6aa
         else {
60e6aa
             switch (proto) {
60e6aa
             case TPROTO_SAS:    /* page added in spl3r02 */
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 013eb336d61d56eb7dc3c67b6551096a8175527a Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 23:41:46 +0800
60e6aa
Subject: [PATCH 17/30] sg_test_rwbuf: Fix incorrect initial value of
60e6aa
 `version_given`.
60e6aa
60e6aa
* With current code, no real code could be execute as
60e6aa
  `version_give` is always true(if not in debug mode).
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_test_rwbuf.c | 4 ++--
60e6aa
 1 file changed, 2 insertions(+), 2 deletions(-)
60e6aa
60e6aa
diff --git a/src/sg_test_rwbuf.c b/src/sg_test_rwbuf.c
60e6aa
index f187ba0..52b7e81 100644
60e6aa
--- a/src/sg_test_rwbuf.c
60e6aa
+++ b/src/sg_test_rwbuf.c
60e6aa
@@ -386,8 +386,8 @@ void usage ()
60e6aa
 
60e6aa
 int main (int argc, char * argv[])
60e6aa
 {
60e6aa
-        bool verbose_given = true;
60e6aa
-        bool version_given = true;
60e6aa
+        bool verbose_given = false;
60e6aa
+        bool version_given = false;
60e6aa
         int sg_fd, res;
60e6aa
         const char * device_name = NULL;
60e6aa
         int times = 1;
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From bf1ee2b1ecc966f50b19bec4126a58b3c4c53111 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Wed, 26 Sep 2018 23:53:52 +0800
60e6aa
Subject: [PATCH 18/30] sg_ses: Remove dead code.
60e6aa
60e6aa
* The `n` is always '>= 1' after the for loop.
60e6aa
* All the possible value between 0x20 to 0x2f is covered by preview
60e6aa
  switch statements.
60e6aa
* The cp is pointing to a stack memory, is always not NULL.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_ses.c | 11 +----------
60e6aa
 1 file changed, 1 insertion(+), 10 deletions(-)
60e6aa
60e6aa
diff --git a/src/sg_ses.c b/src/sg_ses.c
60e6aa
index 29b66b3..9c4b0c0 100644
60e6aa
--- a/src/sg_ses.c
60e6aa
+++ b/src/sg_ses.c
60e6aa
@@ -1405,9 +1405,6 @@ parse_cmd_line(struct opts_t *op, int argc, char *argv[])
60e6aa
             else if (1 == n) {
60e6aa
                 op->page_code_given = true;
60e6aa
                 op->page_code = pc;
60e6aa
-            } else {
60e6aa
-                pr2serr("No dpage found --data= argument\n");
60e6aa
-                goto err_help;
60e6aa
             }
60e6aa
             if (op->verbose > 3) {
60e6aa
                 int k;
60e6aa
@@ -2431,9 +2428,6 @@ find_sas_connector_type(int conn_type, bool abridged, char * buff,
60e6aa
         else if (conn_type < 0x20)
60e6aa
             snprintf(buff, buff_len, "unknown internal wide connector type: "
60e6aa
                      "0x%x", conn_type);
60e6aa
-        else if (conn_type < 0x30)
60e6aa
-            snprintf(buff, buff_len, "unknown internal connector to end "
60e6aa
-                     "device, type: 0x%x", conn_type);
60e6aa
         else if (conn_type < 0x3f)
60e6aa
             snprintf(buff, buff_len, "reserved for internal connector, "
60e6aa
                      "type: 0x%x", conn_type);
60e6aa
@@ -2637,8 +2631,6 @@ enc_status_helper(const char * pad, const uint8_t * statp, int etype,
60e6aa
             printf("%slast 3 bytes (hex): %02x %02x %02x\n", pad, statp[1],
60e6aa
                    statp[2], statp[3]);
60e6aa
             break;
60e6aa
-        default:
60e6aa
-            break;
60e6aa
         }
60e6aa
         break;
60e6aa
     case UI_POWER_SUPPLY_ETC:   /* Uninterruptible power supply */
60e6aa
@@ -4260,8 +4252,7 @@ process_status_dpage(struct sg_pt_base * ptvp, int page_code, uint8_t * resp,
60e6aa
         subenc_nickname_sdg(resp, resp_len);
60e6aa
         break;
60e6aa
     default:
60e6aa
-        printf("Cannot decode response from diagnostic "
60e6aa
-               "page: %s\n", (cp ? cp : "<unknown>"));
60e6aa
+        printf("Cannot decode response from diagnostic page: %s\n", cp);
60e6aa
         hex2stdout(resp, resp_len, 0);
60e6aa
     }
60e6aa
 
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From d1a53f72716e0013c6ff4e76c4ccae575e32e35d Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Thu, 27 Sep 2018 00:07:56 +0800
60e6aa
Subject: [PATCH 19/30] sg_sanitize: Remove dead code.
60e6aa
60e6aa
 * The `has_di` will always be 0 at that line.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_sanitize.c | 5 -----
60e6aa
 1 file changed, 5 deletions(-)
60e6aa
60e6aa
diff --git a/src/sg_sanitize.c b/src/sg_sanitize.c
60e6aa
index b45462f..b810128 100644
60e6aa
--- a/src/sg_sanitize.c
60e6aa
+++ b/src/sg_sanitize.c
60e6aa
@@ -388,11 +388,6 @@ print_dev_id(int fd, uint8_t * sinq_resp, int max_rlen, int verbose)
60e6aa
         n = (SAFE_STD_INQ_RESP_LEN - 4);
60e6aa
     for (k = 0, has_sn = 0, has_di = 0; k < n; ++k) {
60e6aa
         if (VPD_UNIT_SERIAL_NUM == b[4 + k]) {
60e6aa
-            if (has_di) {
60e6aa
-                if (verbose)
60e6aa
-                    pr2serr("VPD_SUPPORTED_VPDS dis-ordered\n");
60e6aa
-                return 0;
60e6aa
-            }
60e6aa
             ++has_sn;
60e6aa
         } else if (VPD_DEVICE_ID == b[4 + k]) {
60e6aa
             ++has_di;
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 880d18e2e0296a91a65f7f94dcd8ad5e2497cfa6 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Thu, 27 Sep 2018 00:09:08 +0800
60e6aa
Subject: [PATCH 20/30] sg_rbuf: Remove dead code.
60e6aa
60e6aa
The `res` is always >=0 at that line.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_rbuf.c | 2 +-
60e6aa
 1 file changed, 1 insertion(+), 1 deletion(-)
60e6aa
60e6aa
diff --git a/src/sg_rbuf.c b/src/sg_rbuf.c
60e6aa
index 61604d3..6b74436 100644
60e6aa
--- a/src/sg_rbuf.c
60e6aa
+++ b/src/sg_rbuf.c
60e6aa
@@ -681,5 +681,5 @@ main(int argc, char * argv[])
60e6aa
     else
60e6aa
         printf("read buffer non-zero\n");
60e6aa
 #endif
60e6aa
-    return (res >= 0) ? res : SG_LIB_CAT_OTHER;
60e6aa
+    return res;
60e6aa
 }
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From d58bc5904989a381b9ab541409b83578a56b75da Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Thu, 27 Sep 2018 00:17:07 +0800
60e6aa
Subject: [PATCH 21/30] sg_luns: Remove dead code.
60e6aa
60e6aa
The `a_method` is always between 0 and 3.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_luns.c | 3 ---
60e6aa
 1 file changed, 3 deletions(-)
60e6aa
60e6aa
diff --git a/src/sg_luns.c b/src/sg_luns.c
60e6aa
index 904b2ce..9115070 100644
60e6aa
--- a/src/sg_luns.c
60e6aa
+++ b/src/sg_luns.c
60e6aa
@@ -306,9 +306,6 @@ decode_lun(const char * leadin, const uint8_t * lunp, bool lu_cong,
60e6aa
                 }
60e6aa
             }
60e6aa
             break;
60e6aa
-        default:
60e6aa
-            printf("%s<<%s: faulty logic>>\n", l_leadin, __func__);
60e6aa
-            break;
60e6aa
         }
60e6aa
         if (next_level)
60e6aa
             continue;
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 601fe8621fa0fb1d2674d67181dd368936354cb4 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Thu, 27 Sep 2018 00:18:57 +0800
60e6aa
Subject: [PATCH 22/30] sg_logs: Fix typo in variable name.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_logs.c | 2 +-
60e6aa
 1 file changed, 1 insertion(+), 1 deletion(-)
60e6aa
60e6aa
diff --git a/src/sg_logs.c b/src/sg_logs.c
60e6aa
index e4f265e..7001ee4 100644
60e6aa
--- a/src/sg_logs.c
60e6aa
+++ b/src/sg_logs.c
60e6aa
@@ -7109,7 +7109,7 @@ main(int argc, char * argv[])
60e6aa
         if (k) {
60e6aa
             if (SG_LIB_CAT_NOT_READY == k)
60e6aa
                 pr2serr("log_select: device not ready\n");
60e6aa
-            else if (SG_LIB_CAT_ILLEGAL_REQ == res)
60e6aa
+            else if (SG_LIB_CAT_ILLEGAL_REQ == k)
60e6aa
                 pr2serr("log_select: field in cdb illegal\n");
60e6aa
             else if (SG_LIB_CAT_INVALID_OP == k)
60e6aa
                 pr2serr("log_select: not supported\n");
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From e921a23e89f91b50929e9f4dc2f5902021f689d9 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Thu, 27 Sep 2018 00:19:40 +0800
60e6aa
Subject: [PATCH 23/30] sg_inq: Remove dead code.
60e6aa
60e6aa
The `support_num` is always between 0 and 7.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_inq.c | 1 -
60e6aa
 1 file changed, 1 deletion(-)
60e6aa
60e6aa
diff --git a/src/sg_inq.c b/src/sg_inq.c
60e6aa
index b32ab87..1664345 100644
60e6aa
--- a/src/sg_inq.c
60e6aa
+++ b/src/sg_inq.c
60e6aa
@@ -3428,7 +3428,6 @@ cmddt_process(int sg_fd, const struct opts_t * op)
60e6aa
                         break;
60e6aa
                 case 6: desc_p = "vendor specific (6)"; break;
60e6aa
                 case 7: desc_p = "reserved (7)"; break;
60e6aa
-                default: desc_p = "impossible value > 7"; break;
60e6aa
                 }
60e6aa
                 if (prnt_cmd) {
60e6aa
                     printf("  Support field: %s [", desc_p);
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 27a19f00c6c58e91296e918a34afb2b2bdcac822 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Thu, 27 Sep 2018 00:20:32 +0800
60e6aa
Subject: [PATCH 24/30] sg_format: Remove dead code.
60e6aa
60e6aa
The `has_di` is always 0 in that line.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_format.c | 6 ------
60e6aa
 1 file changed, 6 deletions(-)
60e6aa
60e6aa
diff --git a/src/sg_format.c b/src/sg_format.c
60e6aa
index af1a033..61ee77f 100644
60e6aa
--- a/src/sg_format.c
60e6aa
+++ b/src/sg_format.c
60e6aa
@@ -700,12 +700,6 @@ print_dev_id(int fd, uint8_t * sinq_resp, int max_rlen,
60e6aa
                 n = (SAFE_STD_INQ_RESP_LEN - 4);
60e6aa
         for (k = 0, has_sn = 0, has_di = 0; k < n; ++k) {
60e6aa
                 if (VPD_UNIT_SERIAL_NUM == b[4 + k]) {
60e6aa
-                        if (has_di) {
60e6aa
-                                if (op->verbose)
60e6aa
-                                        pr2serr("VPD_SUPPORTED_VPDS "
60e6aa
-                                                "dis-ordered\n");
60e6aa
-                                goto out;
60e6aa
-                        }
60e6aa
                         ++has_sn;
60e6aa
                 } else if (VPD_DEVICE_ID == b[4 + k]) {
60e6aa
                         ++has_di;
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 8292e3e96cac1f234f1139161c5e92e29b545da1 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Thu, 27 Sep 2018 00:22:35 +0800
60e6aa
Subject: [PATCH 25/30] sg_dd: Remove dead code.
60e6aa
60e6aa
The `ret` there is always non-zero.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_dd.c | 2 +-
60e6aa
 1 file changed, 1 insertion(+), 1 deletion(-)
60e6aa
60e6aa
diff --git a/src/sg_dd.c b/src/sg_dd.c
60e6aa
index 8696ee7..aa544c7 100644
60e6aa
--- a/src/sg_dd.c
60e6aa
+++ b/src/sg_dd.c
60e6aa
@@ -976,7 +976,7 @@ err_out:
60e6aa
         }
60e6aa
         return may_coe ? 0 : ret;
60e6aa
     } else
60e6aa
-        return ret ? ret : -1;
60e6aa
+        return ret;
60e6aa
 }
60e6aa
 
60e6aa
 
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 50ba84424a1226dfef9a2746fd797cffbc544aad Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Thu, 27 Sep 2018 00:23:49 +0800
60e6aa
Subject: [PATCH 26/30] sg_pt_linux_nvme: Remove dead code.
60e6aa
60e6aa
The `return 0` already stop the `if (dout_len > 0)` check.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 lib/sg_pt_linux_nvme.c | 5 -----
60e6aa
 1 file changed, 5 deletions(-)
60e6aa
60e6aa
diff --git a/lib/sg_pt_linux_nvme.c b/lib/sg_pt_linux_nvme.c
60e6aa
index 18b1374..98feaef 100644
60e6aa
--- a/lib/sg_pt_linux_nvme.c
60e6aa
+++ b/lib/sg_pt_linux_nvme.c
60e6aa
@@ -899,11 +899,6 @@ sntl_senddiag(struct sg_pt_linux_scsi * ptp, const uint8_t * cdbp,
60e6aa
             return 0;
60e6aa
         } else
60e6aa
             return 0;     /* nothing to do */
60e6aa
-        if (dout_len > 0) {
60e6aa
-            if (vb)
60e6aa
-                pr2ws("%s: dout given but PF clear\n", __func__);
60e6aa
-            return SCSI_PT_DO_BAD_PARAMS;
60e6aa
-        }
60e6aa
     }
60e6aa
     if (dout_len < 4) {
60e6aa
         if (vb)
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 570105df861066e0943fc6a7511172acdeb212c0 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Fri, 28 Sep 2018 19:50:11 +0800
60e6aa
Subject: [PATCH 27/30] sg_lib: Remove dead code.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 lib/sg_lib.c | 8 +-------
60e6aa
 1 file changed, 1 insertion(+), 7 deletions(-)
60e6aa
60e6aa
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
60e6aa
index c281cce..e7cac29 100644
60e6aa
--- a/lib/sg_lib.c
60e6aa
+++ b/lib/sg_lib.c
60e6aa
@@ -2123,14 +2123,11 @@ sg_get_command_size(uint8_t opcode)
60e6aa
     switch ((opcode >> 5) & 0x7) {
60e6aa
     case 0:
60e6aa
         return 6;
60e6aa
-    case 1: case 2: case 6: case 7:
60e6aa
-        return 10;
60e6aa
     case 3: case 5:
60e6aa
         return 12;
60e6aa
-        break;
60e6aa
     case 4:
60e6aa
         return 16;
60e6aa
-    default:
60e6aa
+    default:        /* 1, 2, 6, 7 */
60e6aa
         return 10;
60e6aa
     }
60e6aa
 }
60e6aa
@@ -2267,9 +2264,6 @@ sg_get_opcode_name(uint8_t cmd_byte0, int peri_type, int buff_len,
60e6aa
     case 7:
60e6aa
         sg_scnpr(buff, buff_len, "Vendor specific [0x%x]", (int)cmd_byte0);
60e6aa
         break;
60e6aa
-    default:
60e6aa
-        sg_scnpr(buff, buff_len, "Opcode=0x%x", (int)cmd_byte0);
60e6aa
-        break;
60e6aa
     }
60e6aa
 }
60e6aa
 
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 26932a6b4e5a1e844df3edcef86d399391f4b18c Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Thu, 27 Sep 2018 00:33:00 +0800
60e6aa
Subject: [PATCH 28/30] sg_vpd: Fix protantially overflowing of uint64_t.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 src/sg_vpd.c | 6 +++---
60e6aa
 1 file changed, 3 insertions(+), 3 deletions(-)
60e6aa
60e6aa
diff --git a/src/sg_vpd.c b/src/sg_vpd.c
60e6aa
index 081232d..2865af4 100644
60e6aa
--- a/src/sg_vpd.c
60e6aa
+++ b/src/sg_vpd.c
60e6aa
@@ -1929,9 +1929,9 @@ decode_3party_copy_vpd(uint8_t * buff, int len, int do_hex, int pdt,
60e6aa
                 printf("  Maximum identified concurrent copies: %u\n", u);
60e6aa
                 u = sg_get_unaligned_be32(bp + 12);
60e6aa
                 printf("  Maximum segment length: %u\n", u);
60e6aa
-                ull = (1 << bp[16]); /* field is power of 2 */
60e6aa
+                ull = (1 << bp[16]) & UINT64_MAX; /* field is power of 2 */
60e6aa
                 printf("  Data segment granularity: %" PRIu64 "\n", ull);
60e6aa
-                ull = (1 << bp[17]);
60e6aa
+                ull = (1 << bp[17]) & UINT64_MAX;
60e6aa
                 printf("  Inline data granularity: %" PRIu64 "\n", ull);
60e6aa
                 break;
60e6aa
             case 0x9101:
60e6aa
@@ -1943,7 +1943,7 @@ decode_3party_copy_vpd(uint8_t * buff, int len, int do_hex, int pdt,
60e6aa
                 printf(" Held data:\n");
60e6aa
                 u = sg_get_unaligned_be32(bp + 4);
60e6aa
                 printf("  Held data limit: %u\n", u);
60e6aa
-                ull = (1 << bp[8]);
60e6aa
+                ull = (1 << bp[8]) & UINT64_MAX;
60e6aa
                 printf("  Held data granularity: %" PRIu64 "\n", ull);
60e6aa
                 break;
60e6aa
             default:
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 5b2e117dee27ec7cebecd042b2d505f2b6dcb461 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Fri, 28 Sep 2018 19:45:26 +0800
60e6aa
Subject: [PATCH 29/30] sg_lib: Removed dead code.
60e6aa
60e6aa
 * The value 32 stored in `len` is never used afterwords.
60e6aa
 * The `bump` initial value is always been overridden.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 lib/sg_lib.c | 4 ----
60e6aa
 1 file changed, 4 deletions(-)
60e6aa
60e6aa
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
60e6aa
index e7cac29..a691b02 100644
60e6aa
--- a/lib/sg_lib.c
60e6aa
+++ b/lib/sg_lib.c
60e6aa
@@ -545,7 +545,6 @@ sg_decode_transportid_str(const char * lip, uint8_t * bp, int bplen,
60e6aa
     }
60e6aa
     if (NULL == lip)
60e6aa
         lip = "";
60e6aa
-    bump = TRANSPORT_ID_MIN_LEN; /* should be overwritten in all loop paths */
60e6aa
     for (k = 0, n = 0; bplen > 0; ++k, bp += bump, bplen -= bump) {
60e6aa
         if ((k > 0) && only_one)
60e6aa
             break;
60e6aa
@@ -1846,9 +1845,6 @@ sg_get_sense_str(const char * lip, const uint8_t * sbp, int sb_len,
60e6aa
             sg_scnpr(b + r, blen - r, "%s  lba=0x%x\n", lip,
60e6aa
                      sg_get_unaligned_be24(sbp + 1) & 0x1fffff);
60e6aa
         n += sg_scnpr(cbp + n, cblen - n, "%s\n", b);
60e6aa
-        len = sb_len;
60e6aa
-        if (len > 32)
60e6aa
-            len = 32;   /* trim in case there is a lot of rubbish */
60e6aa
     }
60e6aa
 check_raw:
60e6aa
     if (raw_sinfo) {
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa
60e6aa
60e6aa
From 8ebcd159bbc41f63fa96e904dee9307b2ee7aec2 Mon Sep 17 00:00:00 2001
60e6aa
From: Gris Ge <fge@redhat.com>
60e6aa
Date: Fri, 28 Sep 2018 19:59:28 +0800
60e6aa
Subject: [PATCH 30/30] sg_cmds_basic: Check resp for NULL before doing memset.
60e6aa
60e6aa
Signed-off-by: Gris Ge <fge@redhat.com>
60e6aa
---
60e6aa
 lib/sg_cmds_basic.c | 7 +++++++
60e6aa
 1 file changed, 7 insertions(+)
60e6aa
60e6aa
diff --git a/lib/sg_cmds_basic.c b/lib/sg_cmds_basic.c
60e6aa
index e625465..f4021bb 100644
60e6aa
--- a/lib/sg_cmds_basic.c
60e6aa
+++ b/lib/sg_cmds_basic.c
60e6aa
@@ -324,6 +324,13 @@ sg_ll_inquiry_com(struct sg_pt_base * ptvp, bool cmddt, bool evpd, int pg_op,
60e6aa
     uint8_t sense_b[SENSE_BUFF_LEN];
60e6aa
     uint8_t * up;
60e6aa
 
60e6aa
+    if (resp == NULL) {
60e6aa
+        if (verbose)
60e6aa
+            pr2ws("Got NULL `resp` pointer");
60e6aa
+        return SG_LIB_CAT_MALFORMED;
60e6aa
+    }
60e6aa
+
60e6aa
+
60e6aa
     if (cmddt)
60e6aa
         inq_cdb[1] |= 0x2;
60e6aa
     if (evpd)
60e6aa
-- 
60e6aa
1.8.3.1
60e6aa