stgt.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: FUJITA Tomonori <tomof@acm.org>
To: agrover@redhat.com
Cc: tomof@acm.org, stgt@vger.kernel.org
Subject: Re: [PATCH 2/2] Remove incorrect size specifier in spc_lu_init
Date: Fri, 28 Jul 2017 07:59:20 +0900 (JST)	[thread overview]
Message-ID: <20170728.075920.1545942096518959078.tomof@acm.org> (raw)
In-Reply-To: <8ccb226c-e048-467e-425b-ecc7d9ce31f0@redhat.com>

On Thu, 27 Jul 2017 12:16:19 -0700
Andy Grover <agrover@redhat.com> wrote:

>> diff --git a/usr/spc.c b/usr/spc.c
>> index cdb8a2a..b6a77e6 100644
>> --- a/usr/spc.c
>> +++ b/usr/spc.c
>> @@ -2068,7 +2068,7 @@ int spc_lu_init(struct scsi_lu *lu)
>>   	lu->attrs.swp = 0;
>>   	lu->attrs.sense_format = 0;
>>   -	snprintf(lu->attrs.vendor_id, sizeof(lu->attrs.vendor_id),
>> +	scsi_sprintf(lu->attrs.vendor_id, sizeof(lu->attrs.vendor_id),
>>   		 "%-16s", VENDOR_ID);
>>   	snprintf(lu->attrs.product_rev, sizeof(lu->attrs.product_rev),
>>   		 "%s", "0001");
> 
> Well I think there are two cases. First is the above case, where we're
> just filling in our own private fixed width data field. In this case
> this line is fine except the minimum width specifier (16) is larger
> than the actual sizeof(lu->attrs.vendor_id), which is 9. One was added
> to VENDOR_ID_LEN for the field to ensure there was space to
> null-terminate the string, so this is one spot where I think snprintf
> is fine, once the "16" is removed.

Oops, I overlooked that sizeof(lu->attrs.vendor_id) is 9. We were wise
enough to allocate VENDOR_ID_LEN + 1 here :)

As you said, just removing "16" looks fine.

I've pushed your patches, thanks!


> But for all other cases, especially those in smc.c, yes I think we
> need scsi_snprintf(), for properly writing fixed width, NOT
> null-terminated, left-aligned and maybe padded with spaces fields,
> which are common in SCSI.

I'll look at smc.c again later.

      reply	other threads:[~2017-07-27 22:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-18 20:52 [PATCH 0/2] GCC 7 fixes, still need help with smc.c Andy Grover
2017-07-18 20:52 ` [PATCH 1/2] Fix header warning with GCC 7 for major() Andy Grover
2017-07-18 20:52 ` [PATCH 2/2] Remove incorrect size specifier in spc_lu_init Andy Grover
2017-07-27  7:11   ` FUJITA Tomonori
2017-07-27 19:16     ` Andy Grover
2017-07-27 22:59       ` FUJITA Tomonori [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170728.075920.1545942096518959078.tomof@acm.org \
    --to=tomof@acm.org \
    --cc=agrover@redhat.com \
    --cc=stgt@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).