From: Bart Van Assche <bvanassche@acm.org>
To: Wang Xiayang <xywang.sjtu@sjtu.edu.cn>
Cc: qla2xxx-upstream@qlogic.com, linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: qla2xxx: replace snprintf with strscpy
Date: Wed, 14 Aug 2019 08:25:41 -0700 [thread overview]
Message-ID: <80cad672-d727-8e96-4e2c-ffc33ca6ff55@acm.org> (raw)
In-Reply-To: <20190725054653.30729-1-xywang.sjtu@sjtu.edu.cn>
On 7/24/19 10:46 PM, Wang Xiayang wrote:
> As commit a86028f8e3ee ("staging: most: sound: replace snprintf
> with strscpy") suggested, using snprintf without a format specifier
> is potentially risky if a0->vendor_name or a0->vendor_pn mistakenly
> contain format specifiers. In addition, as compared in the
> implementation, strscpy looks more light-weight than snprintf.
>
> This patch does not incur any functional change.
>
> Signed-off-by: Wang Xiayang <xywang.sjtu@sjtu.edu.cn>
> ---
> drivers/scsi/qla2xxx/qla_init.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
> index 4059655639d9..068b54218ff4 100644
> --- a/drivers/scsi/qla2xxx/qla_init.c
> +++ b/drivers/scsi/qla2xxx/qla_init.c
> @@ -3461,12 +3461,12 @@ static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
> int leftover, len;
>
> memset(str, 0, STR_LEN);
> - snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
> + strscpy(str, a0->vendor_name, SFF_VEN_NAME_LEN+1);
> ql_dbg(ql_dbg_init, vha, 0x015a,
> "SFP MFG Name: %s\n", str);
>
> memset(str, 0, STR_LEN);
> - snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
> + strscpy(str, a0->vendor_pn, SFF_PART_NAME_LEN+1);
> ql_dbg(ql_dbg_init, vha, 0x015c,
> "SFP Part Name: %s\n", str);
From qla_def.h:
/* Refer to SNIA SFF 8247 */
struct sff_8247_a0 {
[ ... ]
u8 vendor_name[SFF_VEN_NAME_LEN]; /* offset 20/14h */
u8 vendor_pn[SFF_PART_NAME_LEN]; /* part number */
So I think that using SFF_PART_NAME_LEN+1 as length limit is wrong.
Himanshu, do you perhaps know whether or not the vendor_name and
vendor_pn arrays should be '\0'-terminated in struct sff_8247_a0?
Thanks,
Bart.
next prev parent reply other threads:[~2019-08-14 15:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190725054653.30729-1-xywang.sjtu@sjtu.edu.cn>
2019-08-14 14:08 ` [PATCH] scsi: qla2xxx: replace snprintf with strscpy Himanshu Madhani
2019-08-14 15:25 ` Bart Van Assche [this message]
2019-08-14 18:33 ` Himanshu Madhani
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=80cad672-d727-8e96-4e2c-ffc33ca6ff55@acm.org \
--to=bvanassche@acm.org \
--cc=linux-scsi@vger.kernel.org \
--cc=qla2xxx-upstream@qlogic.com \
--cc=xywang.sjtu@sjtu.edu.cn \
/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