From: James Bottomley <jejb@linux.ibm.com>
To: Chuhong Yuan <hslester96@gmail.com>
Cc: Adam Radford <aradford@gmail.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: 3w-sas: Fix unterminated strncpy
Date: Tue, 30 Jul 2019 07:56:37 -0700 [thread overview]
Message-ID: <1564498597.4300.10.camel@linux.ibm.com> (raw)
In-Reply-To: <20190730084047.26482-1-hslester96@gmail.com>
On Tue, 2019-07-30 at 16:40 +0800, Chuhong Yuan wrote:
> strncpy(dest, src, strlen(src)) leads to unterminated
> dest, which is dangerous.
I don't buy that. The structure is only used for the
TW_IOCTL_GET_COMPATIBILITY_INFO ioctl and all the fields for that are
fixed width and are copied over as such.
> Here driver_version's len is 32 and TW_DRIVER_VERSION
> is shorter than 32.
> Therefore strcpy is OK.
The best practice for copying a string to a fixed width destination
that does get printed within the kernel would be what the 3w-9xxx.c
does
strlcpy(tw_dev->tw_compat_info.driver_version, TW_DRIVER_VERSION,
sizeof(tw_dev->tw_compat_info.driver_version));
But as I said, it doesn't really matter for a fixed width field that's
never printed within the kernel.
James
next prev parent reply other threads:[~2019-07-30 14:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-30 8:40 [PATCH] scsi: 3w-sas: Fix unterminated strncpy Chuhong Yuan
2019-07-30 14:56 ` James Bottomley [this message]
2019-08-05 6:22 ` Chuhong Yuan
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=1564498597.4300.10.camel@linux.ibm.com \
--to=jejb@linux.ibm.com \
--cc=aradford@gmail.com \
--cc=hslester96@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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 NNTP newsgroup(s).