aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2018-07-25 15:00:20 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2018-07-25 15:00:20 +0000
commit9236f11e7389ec4658b06b3835ad4a6cceca9d50 (patch)
tree16ac647678dd531cd550bf29b4290e3361b4930d
parent519744574345fd358009dc5a167d83715c3f4813 (diff)
downloadsg3_utils-9236f11e7389ec4658b06b3835ad4a6cceca9d50.tar.gz
sg_format: when changing block size allow for Mode Select rejecting SP=1 (Save Page): repeat with SP=0; gcc-8 warning cleanups
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@785 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog4
-rw-r--r--doc/sg3_utils.810
-rw-r--r--doc/sg_format.836
-rw-r--r--src/sg_dd.c8
-rw-r--r--src/sg_format.c115
-rw-r--r--src/sg_map26.c15
-rw-r--r--src/sg_read.c6
-rw-r--r--src/sg_ses.c10
-rw-r--r--src/sg_write_long.c5
-rw-r--r--src/sg_write_same.c5
-rw-r--r--src/sginfo.c12
-rw-r--r--src/sgm_dd.c8
-rw-r--r--src/sgp_dd.c6
13 files changed, 117 insertions, 123 deletions
diff --git a/ChangeLog b/ChangeLog
index 1138b966..225b6368 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and
some description at the top of its ".c" file. All utilities in the main
directory have their own "man" pages. There is also a sg3_utils man page.
-Changelog for sg3_utils-1.43 [20180716] [svn: r784]
+Changelog for sg3_utils-1.43 [20180724] [svn: r785]
- sg_write_x: where x can be normal, atomic, or(write),
same, scattered, or stream writes with 16 or 32 byte
cdbs (sbc4r04 for atomic, sbc4r11 for scattered)
@@ -17,6 +17,8 @@ Changelog for sg3_utils-1.43 [20180716] [svn: r784]
- add --quick option to skip reconsideration time
- extend --wait timeout to 40 hours for disk sizes
> 4 TB and 80 hours if > 8 TB
+ - when changing block size allow for Mode Select
+ rejecting SP=1 (Save Page): repeat with SP=0
- sg_decode sense: add --cdb and --err=ES options
- sg_ses: handle 2 bit EIIOE field in aes dpage
- increase join array size from 260 to 520 elements
diff --git a/doc/sg3_utils.8 b/doc/sg3_utils.8
index 20f7d7ac..1c5ba619 100644
--- a/doc/sg3_utils.8
+++ b/doc/sg3_utils.8
@@ -32,10 +32,12 @@ A good overview of various SCSI standards can be seen in
http://www.t10.org/scsi\-3.htm with the SCSI command sets in the upper part
of the diagram. The highest level (i.e. most abstract) document is the SCSI
Architecture Model (SAM) with SAM\-5 being the most recent standard (ANSI
-INCITS 447\-2008) although SAM\-5 should be released soon. SCSI commands in
-common with all device types can be found in SPC of which SPC\-5 is the
-latest major version. Block device specific commands (e.g. as used by disks)
-are in SBC, those for tape drives in SSC and those for CD/DVD/BD drives in
+INCITS 515\-2016) with the most recent draft being SAM\-6 revision 4 . SCSI
+commands in common with all device types can be found in SCSI Primary
+Commands (SPC) of which SPC\-4 is the most recent standard (ANSI INCITS
+513-2015). The most recent SPC draft is SPC\-5 revision 19. Block device
+specific commands (e.g. as used by disks) are in SBC, those for tape drives
+in SSC, those for SCSI enclosures in SES and those for CD/DVD/BD drives in
MMC.
.PP
It is becoming more common to control ATA disks with the SCSI command set.
diff --git a/doc/sg_format.8 b/doc/sg_format.8
index cb029510..5a54998f 100644
--- a/doc/sg_format.8
+++ b/doc/sg_format.8
@@ -1,4 +1,4 @@
-.TH SG_FORMAT "8" "May 2018" "sg3_utils\-1.43" SG3_UTILS
+.TH SG_FORMAT "8" "July 2018" "sg3_utils\-1.43" SG3_UTILS
.SH NAME
sg_format \- format, resize a SCSI disk or format a tape
.SH SYNOPSIS
@@ -133,20 +133,22 @@ utilities (e.g. sg_turs(8) or sg_requests(8)). This option and \fI\-\-wait\fR
are mutually exclusive.
.TP
\fB\-t\fR, \fB\-\-ffmt\fR=\fIFFMT\fR
-\fIFFMT\fR is placed in a field of the same name in the FORMAT UNIT cdb.
-The field was introduced in SBC\-4 revision 10. The default value is 0 which
-implies the former action which is typically to overwrite to all blocks on the
-\fIDEVICE\fR. That can take a long time (e.g. with hard disks over 10 TB in
-size).
+\fIFFMT\fR (fast format) is placed in a field of the same name in the FORMAT
+UNIT cdb. The field was introduced in SBC\-4 revision 10. The default value
+is 0 which implies the former action which is typically to overwrite to all
+blocks on the \fIDEVICE\fR. That can take a long time (e.g. with hard disks
+over 10 TB in size).
.br
\fIFFMT\fR has values 1 and 2 for fast format with 3 being reserved
-currently. The difference between 1 and 2 concerns read operations on LBAs to
-which no data has been written to, after the fast format. When \fIFFMT\fR
-is 1 the read operation should return "unspecified logical block data" and
-complete without error. When \fIFFMT\fR is 2 the read operation may
-yield check condition status with a sense key set to hardware error, medium
-error or command aborted. See SBC\-4 revision 10 section 4.35 for more
-details.
+currently. These two values include this description: "The device server
+initializes the medium ... without overwriting the medium (i.e. resources
+for managing medium access are initialized and the medium is not written)".
+The difference between 1 and 2 concerns read operations on LBAs to which no
+data has been written to, after the fast format. When \fIFFMT\fR is 1 the
+read operation should return "unspecified logical block data" and complete
+without error. When \fIFFMT\fR is 2 the read operation may yield check
+condition status with a sense key set to hardware error, medium error or
+command aborted. See SBC\-4 revision 10 section 4.35 for more details.
.TP
\fB\-f\fR, \fB\-\-fmtpinfo\fR=\fIFPI\fR
sets the FMTPINFO field in the FORMAT UNIT cdb to a value between 0 and 3.
@@ -201,6 +203,12 @@ parameters (e.g. when '\-\-pie=PIE' is greater than zero).
\fIMP\fR is a mode page number (0 to 62 inclusive) that will be used for
reading and perhaps changing the device logical block size. The default
is 1 which is the Read\-Write Error Recovery mode page.
+.br
+Preferably the chosen (or default) mode page should be saveable (i.e.
+accept the SP bit set in the MODE SELECT command used when the logical
+block size is being changed). Recent version of this utility will retry a
+MODE SELECT if the SP=1 variant fails with a sense key of ILLEGAL REQUEST.
+The retry that same MODE SELECT command with SP=0 .
.TP
\fB\-P\fR, \fB\-\-pfu\fR=\fIPFU\fR
sets the "Protection Field Usage" field in the parameter block associated
@@ -285,7 +293,7 @@ format; 1 to partition a volume and 2 to do a default format then partition.
where \fISECS\fR is the FORMAT UNIT or FORMAT MEDIUM command timeout in
seconds. \fISECS\fR will only be used if it exceeds the internal timeout
which is 20 seconds if the IMMED bit is set and 72000 seconds (20 hours)
-or higher if the IMMED bit is not set. If the didk unit exceeds 4 TB then
+or higher if the IMMED bit is not set. If the disk size exceeds 4 TB then
the timeout value is increased to 144000 seconds (40 hours). And if it is
greater than 8 TB then the timeout value is increased to 288000 seconds (80
hours). If the timeout is exceeded then the operating system will typically
diff --git a/src/sg_dd.c b/src/sg_dd.c
index 119ade2a..9dd5f2c1 100644
--- a/src/sg_dd.c
+++ b/src/sg_dd.c
@@ -62,7 +62,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "6.02 20180705";
+static const char * version_str = "6.03 20180723";
#define ME "sg_dd: "
@@ -1603,7 +1603,7 @@ main(int argc, char * argv[])
pr2serr("Second IFILE argument??\n");
return SG_LIB_SYNTAX_ERROR;
} else
- strncpy(inf, buf, INOUTF_SZ);
+ strncpy(inf, buf, INOUTF_SZ - 1);
} else if (0 == strcmp(key, "iflag")) {
if (process_flags(buf, &iflag)) {
pr2serr(ME "bad argument to 'iflag='\n");
@@ -1619,13 +1619,13 @@ main(int argc, char * argv[])
pr2serr("Second OFILE argument??\n");
return SG_LIB_CONTRADICT;
} else
- strncpy(outf, buf, INOUTF_SZ);
+ strncpy(outf, buf, INOUTF_SZ - 1);
} else if (strcmp(key, "of2") == 0) {
if ('\0' != out2f[0]) {
pr2serr("Second OFILE2 argument??\n");
return SG_LIB_CONTRADICT;
} else
- strncpy(out2f, buf, INOUTF_SZ);
+ strncpy(out2f, buf, INOUTF_SZ - 1);
} else if (0 == strcmp(key, "oflag")) {
if (process_flags(buf, &oflag)) {
pr2serr(ME "bad argument to 'oflag='\n");
diff --git a/src/sg_format.c b/src/sg_format.c
index f8b90891..7c34b43f 100644
--- a/src/sg_format.c
+++ b/src/sg_format.c
@@ -38,7 +38,7 @@
#include "sg_pr2serr.h"
#include "sg_pt.h"
-static const char * version_str = "1.51 20180626";
+static const char * version_str = "1.52 20180723";
#define RW_ERROR_RECOVERY_PAGE 1 /* can give alternate with --mode=MP */
@@ -821,7 +821,7 @@ main(int argc, char **argv)
{
bool prob = false;
int fd, res, calc_len, bd_len, dev_specific_param;
- int offset, j, n, bd_blk_len, len, pdt, rsp_len;
+ int offset, j, bd_blk_len, pdt, rsp_len, vb;
int resid = 0;
int ret = 0;
uint64_t ull;
@@ -1033,6 +1033,7 @@ main(int argc, char **argv)
pr2serr("sg_format version: %s\n", version_str);
return 0;
}
+ vb = op->verbose;
if (NULL == op->device_name) {
pr2serr("no DEVICE name given\n\n");
usage();
@@ -1080,7 +1081,7 @@ main(int argc, char **argv)
}
if ((fd = sg_cmds_open_device(op->device_name, false /* rw=false */,
- op->verbose)) < 0) {
+ vb)) < 0) {
pr2serr("error opening device file: %s: %s\n",
op->device_name, safe_strerror(-fd));
return sg_convert_errno(-fd);
@@ -1116,13 +1117,13 @@ again_with_long_lba:
if (op->mode6)
res = sg_ll_mode_sense6(fd, false /* DBD */, 0 /* current */,
op->mode_page, 0 /* subpage */, dbuff,
- MAX_BUFF_SZ, true, op->verbose);
+ MAX_BUFF_SZ, true, vb);
else
res = sg_ll_mode_sense10_v2(fd, op->long_lba, false /* DBD */,
0 /* current */, op->mode_page,
0 /* subpage */, dbuff,
MAX_BUFF_SZ, 0, &resid, true,
- op->verbose);
+ vb);
ret = res;
if (res) {
if (SG_LIB_CAT_ILLEGAL_REQ == res) {
@@ -1135,12 +1136,11 @@ again_with_long_lba:
"[mode_page %d not supported?]\n",
(op->mode6 ? 6 : 10), op->mode_page);
} else {
- sg_get_category_sense_str(res, sizeof(b), b,
- op->verbose);
+ sg_get_category_sense_str(res, sizeof(b), b, vb);
pr2serr("MODE SENSE (%d) command: %s\n",
(op->mode6 ? 6 : 10), b);
}
- if (0 == op->verbose)
+ if (0 == vb)
pr2serr(" try '-v' for more information\n");
goto out;
}
@@ -1198,7 +1198,7 @@ again_with_long_lba:
ull = op->long_lba ? sg_get_unaligned_be64(dbuff + offset) :
sg_get_unaligned_be32(dbuff + offset);
if ((! op->long_lba) && (0xffffffff == ull)) {
- if (op->verbose)
+ if (vb)
pr2serr("Mode sense number of blocks maxed "
"out, set longlba\n");
op->long_lba = true;
@@ -1229,39 +1229,6 @@ again_with_long_lba:
((op->blk_size > 0) && (op->blk_size != bd_blk_len))))) {
/* want to run MODE SELECT */
-/* Working Draft SCSI Primary Commands - 3 (SPC-3) pg 255
-**
-** If the SCSI device doesn't support changing its capacity by changing
-** the NUMBER OF BLOCKS field using the MODE SELECT command, the value
-** in the NUMBER OF BLOCKS field is ignored. If the device supports changing
-** its capacity by changing the NUMBER OF BLOCKS field, then the
-** NUMBER OF BLOCKS field is interpreted as follows:
-** a) If the number of blocks is set to zero, the device shall retain
-** its current capacity if the block size has not changed. If the
-** number of blocks is set to zero and the block size has changed,
-** the device shall be set to its maximum capacity when the new
-** block size takes effect;
-**
-** b) If the number of blocks is greater than zero and less than or
-** equal to its maximum capacity, the device shall be set to that
-** number of blocks. If the block size has not changed, the device
-** shall not become format corrupted. This capacity setting shall be
-** retained through power cycles, hard resets, logical unit resets,
-** and I_T nexus losses;
-**
-** c) If the number of blocks field is set to a value greater than the
-** maximum capacity of the device and less than FFFF FFFFh, then the
-** command is terminated with a CHECK CONDITION status. The sense key
-** is set to ILLEGAL REQUEST. The device shall retain its previous
-** block descriptor settings; or
-**
-** d) If the number of blocks is set to FFFF FFFFh, the device shall be
-** set to its maximum capacity. If the block size has not changed,
-** the device shall not become format corrupted. This capacity setting
-** shall be retained through power cycles, hard resets, logical unit
-** resets, and I_T nexus losses.
-*/
-
if (prob) {
pr2serr("Need to perform MODE SELECT (to change "
"number or blocks or block length)\n");
@@ -1270,19 +1237,18 @@ again_with_long_lba:
ret = SG_LIB_CAT_MALFORMED;
goto out;
}
- if (op->blk_count != 0) {
- len = (op->long_lba ? 8 : 4);
- for (j = 0; j < len; ++j) {
- n = (len - j - 1) * 8;
- dbuff[offset + j] =
- (op->blk_count >> n) & 0xff;
- }
+ if (op->blk_count != 0) { /* user supplied blk count */
+ if (op->long_lba)
+ sg_put_unaligned_be64(op->blk_count,
+ dbuff + offset);
+ else
+ sg_put_unaligned_be32(op->blk_count,
+ dbuff + offset);
} else if ((op->blk_size > 0) &&
- (op->blk_size != bd_blk_len)) {
- len = (op->long_lba ? 8 : 4);
- for (j = 0; j < len; ++j)
- dbuff[offset + j] = 0;
- }
+ (op->blk_size != bd_blk_len))
+ /* 0 implies max capacity with new LB size */
+ memset(dbuff + offset, 0, op->long_lba ? 8 : 4);
+
if ((op->blk_size > 0) && (op->blk_size != bd_blk_len)) {
if (op->long_lba)
sg_put_unaligned_be32((uint32_t)op->blk_size,
@@ -1291,23 +1257,34 @@ again_with_long_lba:
sg_put_unaligned_be24((uint32_t)op->blk_size,
dbuff + offset + 5);
}
- if (op->dry_run)
+ if (op->dry_run) {
pr2serr("Due to --dry-run option bypass MODE "
"SELECT(%d)command\n", (op->mode6 ? 6 : 10));
- else if (op->mode6)
- res = sg_ll_mode_select6(fd, true /* PF */,
- true /* SP */, dbuff,
- calc_len, true, op->verbose);
- else
- res = sg_ll_mode_select10(fd, true /* PF */,
- true /* SP */, dbuff,
- calc_len, true, op->verbose);
+ res = 0;
+ } else {
+ bool sp = true; /* may not be able to save pages */
+
+again_sp_false:
+ if (op->mode6)
+ res = sg_ll_mode_select6(fd, true /* PF */,
+ sp, dbuff, calc_len,
+ true, vb);
+ else
+ res = sg_ll_mode_select10(fd, true /* PF */,
+ sp, dbuff, calc_len,
+ true, vb);
+ if ((SG_LIB_CAT_ILLEGAL_REQ == res) && sp) {
+ pr2serr("Try MODE SELECT again with SP=0 "
+ "this time\n");
+ sp = false;
+ goto again_sp_false;
+ }
+ }
ret = res;
if (res) {
- sg_get_category_sense_str(res, sizeof(b), b,
- op->verbose);
+ sg_get_category_sense_str(res, sizeof(b), b, vb);
pr2serr("MODE SELECT command: %s\n", b);
- if (0 == op->verbose)
+ if (0 == vb)
pr2serr(" try '-v' for more information\n");
goto out;
}
@@ -1364,7 +1341,7 @@ skip_f_unit_reconsider:
ret = res;
if (res) {
pr2serr("FORMAT UNIT failed\n");
- if (0 == op->verbose)
+ if (0 == vb)
pr2serr(" try '-v' for more "
"information\n");
}
@@ -1399,7 +1376,7 @@ skip_f_med_reconsider:
ret = res;
if (res) {
pr2serr("FORMAT MEDIUM failed\n");
- if (0 == op->verbose)
+ if (0 == vb)
pr2serr(" try '-v' for more "
"information\n");
}
@@ -1411,7 +1388,7 @@ out:
if (0 == ret)
ret = sg_convert_errno(-res);
}
- if (0 == op->verbose) {
+ if (0 == vb) {
if (! sg_if_can2stderr("sg_format failed: ", ret))
pr2serr("Some error occurred, try again with '-v' "
"or '-vv' for more information\n");
diff --git a/src/sg_map26.c b/src/sg_map26.c
index 46cb3576..a48fcda5 100644
--- a/src/sg_map26.c
+++ b/src/sg_map26.c
@@ -45,7 +45,7 @@
#endif
#include "sg_lib.h"
-static const char * version_str = "1.15 20171019";
+static const char * version_str = "1.16 20180724";
#define ME "sg_map26: "
@@ -60,8 +60,8 @@ static const char * version_str = "1.15 20171019";
#define NT_REG 8
#define NT_DIR 9
-#define NAME_LEN_MAX 260
-#define D_NAME_LEN_MAX 516
+#define NAME_LEN_MAX 256
+#define D_NAME_LEN_MAX 520
#ifndef SCSI_CHANGER_MAJOR
#define SCSI_CHANGER_MAJOR 86
@@ -344,9 +344,8 @@ nd_match_scandir_select(const struct dirent * s)
}
if ((! symlnk) && (-1 == nd_match.majj) && (-1 == nd_match.minn))
return 1;
- strncpy(name, nd_match.dir_name, NAME_LEN_MAX);
- strcat(name, "/");
- strncat(name, s->d_name, NAME_LEN_MAX);
+ snprintf(name, sizeof(name), "%.*s/%.*s", NAME_LEN_MAX,
+ nd_match.dir_name, NAME_LEN_MAX, s->d_name);
memset(&st, 0, sizeof(st));
if (stat(name, &st) < 0)
return 0;
@@ -374,7 +373,7 @@ list_matching_nodes(const char * dir_name, int file_type, int majj, int minn,
struct dirent ** namelist;
int num, k;
- strncpy(nd_match.dir_name, dir_name, D_NAME_LEN_MAX);
+ strncpy(nd_match.dir_name, dir_name, D_NAME_LEN_MAX - 1);
nd_match.file_type = file_type;
nd_match.majj = majj;
nd_match.minn = minn;
@@ -1066,7 +1065,7 @@ main(int argc, char * argv[])
switch (c) {
case 'd':
- strncpy(device_dir, optarg, sizeof(device_dir));
+ strncpy(device_dir, optarg, sizeof(device_dir) - 1);
do_dev_dir = true;
break;
case 'g':
diff --git a/src/sg_read.c b/src/sg_read.c
index 0b3386fa..13058431 100644
--- a/src/sg_read.c
+++ b/src/sg_read.c
@@ -53,7 +53,7 @@
#include "sg_pr2serr.h"
-static const char * version_str = "1.32 20180523";
+static const char * version_str = "1.33 20180724";
#define DEF_BLOCK_SIZE 512
#define DEF_BLOCKS_PER_TRANSFER 128
@@ -487,7 +487,7 @@ main(int argc, char * argv[])
else if (0 == strcmp(key,"fua"))
fua = !! sg_get_num(buf);
else if (strcmp(key,"if") == 0)
- strncpy(inf, buf, INF_SZ);
+ strncpy(inf, buf, INF_SZ - 1);
else if (0 == strcmp(key,"mmap"))
do_mmap = !! sg_get_num(buf);
else if (0 == strcmp(key,"no_dxfer"))
@@ -495,7 +495,7 @@ main(int argc, char * argv[])
else if (0 == strcmp(key,"odir"))
do_odir = !! sg_get_num(buf);
else if (strcmp(key,"of") == 0)
- strncpy(outf, buf, INF_SZ);
+ strncpy(outf, buf, INF_SZ - 1);
else if (0 == strcmp(key,"skip")) {
skip = sg_get_llnum(buf);
if (-1 == skip) {
diff --git a/src/sg_ses.c b/src/sg_ses.c
index 7874c41b..b977a6e6 100644
--- a/src/sg_ses.c
+++ b/src/sg_ses.c
@@ -36,7 +36,7 @@
* commands tailored for SES (enclosure) devices.
*/
-static const char * version_str = "2.41 20180716"; /* ses4r02 */
+static const char * version_str = "2.42 20180724"; /* ses4r02 */
#define MX_ALLOC_LEN ((64 * 1024) - 4) /* max allowable for big enclosures */
#define MX_ELEM_HDR 1024
@@ -984,6 +984,7 @@ parse_index(struct opts_t *op)
const char * cc3p;
const struct element_type_t * etp;
char b[64];
+ const int blen = sizeof(b);
op->ind_given = true;
n2 = 0;
@@ -1011,20 +1012,19 @@ parse_index(struct opts_t *op)
if (n2 > 0)
op->ind_indiv_last = n2;
n = cp - op->index_str;
- if (n >= (int)sizeof(b)) {
+ if (n >= (blen - 1)) {
pr2serr("bad argument to '--index', string prior to comma too "
"long\n");
return SG_LIB_SYNTAX_ERROR;
}
} else { /* no comma found in index_str */
n = strlen(op->index_str);
- if (n >= (int)sizeof(b)) {
+ if (n >= (blen - 1)) {
pr2serr("bad argument to '--index', string too long\n");
return SG_LIB_SYNTAX_ERROR;
}
}
- strncpy(b, op->index_str, n);
- b[n] = '\0';
+ snprintf(b, blen, "%.*s", n, op->index_str);
if (0 == strcmp("-1", b)) {
if (cp) {
pr2serr("bad argument to '--index', unexpected '-1' type header "
diff --git a/src/sg_write_long.c b/src/sg_write_long.c
index 71d72b34..41c6b8bc 100644
--- a/src/sg_write_long.c
+++ b/src/sg_write_long.c
@@ -35,7 +35,7 @@
#include "sg_cmds_extra.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.20 20180628";
+static const char * version_str = "1.21 20180723";
#define MAX_XFER_LEN (15 * 1024)
@@ -139,7 +139,8 @@ main(int argc, char * argv[])
usage();
return 0;
case 'i':
- strncpy(file_name, optarg, sizeof(file_name));
+ strncpy(file_name, optarg, sizeof(file_name) - 1);
+ file_name[sizeof(file_name) - 1] = '\0';
break;
case 'l':
ll = sg_get_llnum(optarg);
diff --git a/src/sg_write_same.c b/src/sg_write_same.c
index e8458517..f589d0ea 100644
--- a/src/sg_write_same.c
+++ b/src/sg_write_same.c
@@ -31,7 +31,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.25 20180628";
+static const char * version_str = "1.26 20180723";
#define ME "sg_write_same: "
@@ -357,7 +357,8 @@ main(int argc, char * argv[])
usage();
return 0;
case 'i':
- strncpy(op->ifilename, optarg, sizeof(op->ifilename));
+ strncpy(op->ifilename, optarg, sizeof(op->ifilename) - 1);
+ op->ifilename[sizeof(op->ifilename) - 1] = '\0';
if_given = true;
break;
case 'l':
diff --git a/src/sginfo.c b/src/sginfo.c
index 6569140a..f3b87deb 100644
--- a/src/sginfo.c
+++ b/src/sginfo.c
@@ -122,7 +122,7 @@
#define _GNU_SOURCE 1
#endif
-static const char * version_str = "2.40 [20180219]";
+static const char * version_str = "2.41 [20180724]";
#include <stdio.h>
#include <string.h>
@@ -3390,7 +3390,7 @@ static Sg_map sg_map_arr[MAX_SG_DEVS + 1];
static void
show_devices(int raw)
{
- int k, j, fd, err, bus;
+ int k, j, fd, err, bus, n;
My_scsi_idlun m_idlun;
char name[MDEV_NAME_SZ];
char dev_name[MDEV_NAME_SZ + 6];
@@ -3462,8 +3462,12 @@ show_devices(int raw)
sg_map_arr[j].channel = (m_idlun.mux4 >> 16) & 0xff;
sg_map_arr[j].lun = (m_idlun.mux4 >> 8) & 0xff;
sg_map_arr[j].target_id = m_idlun.mux4 & 0xff;
- tmpptr=(char *)malloc(strlen(dev_name)+1);
- strncpy(tmpptr,dev_name,strlen(dev_name)+1);
+ n = strlen(dev_name);
+ /* memory leak ... no free()s for this malloc() */
+ tmpptr = (char *)malloc(n + 1);
+ snprintf(tmpptr, n + 1, "%.*s", n, dev_name);
+ /* strncpy(tmpptr,dev_name,strlen(dev_name)+1); */
+
sg_map_arr[j].dev_name = tmpptr;
#if 0
printf("[scsi%d ch=%d id=%d lun=%d %s] ", sg_map_arr[j].bus,
diff --git a/src/sgm_dd.c b/src/sgm_dd.c
index cc3fdd4a..912d7593 100644
--- a/src/sgm_dd.c
+++ b/src/sgm_dd.c
@@ -66,7 +66,7 @@
#include "sg_pr2serr.h"
-static const char * version_str = "1.58 20180705";
+static const char * version_str = "1.59 20180724";
#define DEF_BLOCK_SIZE 512
#define DEF_BLOCKS_PER_TRANSFER 128
@@ -752,7 +752,7 @@ main(int argc, char * argv[])
for (k = 1; k < argc; k++) {
if (argv[k])
- strncpy(str, argv[k], STR_SZ);
+ snprintf(str, STR_SZ, "%s", argv[k]);
else
continue;
for (key = str, buf = key; *buf && *buf != '=';)
@@ -807,7 +807,7 @@ main(int argc, char * argv[])
pr2serr("Second 'if=' argument??\n");
return SG_LIB_CONTRADICT;
} else
- strncpy(inf, buf, INOUTF_SZ);
+ snprintf(inf, INOUTF_SZ, "%s", buf);
} else if (0 == strcmp(key, "iflag")) {
if (process_flags(buf, &in_flags)) {
pr2serr(ME "bad argument to 'iflag'\n");
@@ -818,7 +818,7 @@ main(int argc, char * argv[])
pr2serr("Second 'of=' argument??\n");
return SG_LIB_CONTRADICT;
} else
- strncpy(outf, buf, INOUTF_SZ);
+ snprintf(outf, INOUTF_SZ, "%s", buf);
} else if (0 == strcmp(key, "oflag")) {
if (process_flags(buf, &out_flags)) {
pr2serr(ME "bad argument to 'oflag'\n");
diff --git a/src/sgp_dd.c b/src/sgp_dd.c
index bf8dfb82..fdbe61d9 100644
--- a/src/sgp_dd.c
+++ b/src/sgp_dd.c
@@ -60,7 +60,7 @@
#include "sg_pr2serr.h"
-static const char * version_str = "5.67 20180627";
+static const char * version_str = "5.68 20180724";
#define DEF_BLOCK_SIZE 512
#define DEF_BLOCKS_PER_TRANSFER 128
@@ -1253,7 +1253,7 @@ main(int argc, char * argv[])
pr2serr("Second 'if=' argument??\n");
return SG_LIB_SYNTAX_ERROR;
} else
- strncpy(inf, buf, INOUTF_SZ);
+ snprintf(inf, INOUTF_SZ, "%s", buf);
} else if (0 == strcmp(key, "iflag")) {
if (process_flags(buf, &rcoll.in_flags)) {
pr2serr("%sbad argument to 'iflag='\n", my_name);
@@ -1270,7 +1270,7 @@ main(int argc, char * argv[])
pr2serr("Second 'of=' argument??\n");
return SG_LIB_SYNTAX_ERROR;
} else
- strncpy(outf, buf, INOUTF_SZ);
+ snprintf(outf, INOUTF_SZ, "%s", buf);
} else if (0 == strcmp(key, "oflag")) {
if (process_flags(buf, &rcoll.out_flags)) {
pr2serr("%sbad argument to 'oflag='\n", my_name);