linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <yang.yang29@zte.com.cn>
To: <wg@grandegger.com>
Cc: <mkl@pengutronix.de>, <davem@davemloft.net>,
	<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>,
	<mailhol.vincent@wanadoo.fr>, <stefan.maetje@esd.eu>,
	<socketcan@hartkopp.net>, <dzm91@hust.edu.cn>,
	<julia.lawall@inria.fr>, <gustavoars@kernel.org>,
	<linux-can@vger.kernel.org>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <xu.panda@zte.com.cn>,
	<yang.yang29@zte.com.cn>
Subject: [PATCH linux-next] can: ucan: use strscpy() to instead of strncpy()
Date: Wed, 7 Dec 2022 09:09:09 +0800 (CST)	[thread overview]
Message-ID: <202212070909095189693@zte.com.cn> (raw)

From: Xu Panda <xu.panda@zte.com.cn>

The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL terminated strings.

Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
---
 drivers/net/can/usb/ucan.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/usb/ucan.c b/drivers/net/can/usb/ucan.c
index ffa38f533c35..159e25ffa337 100644
--- a/drivers/net/can/usb/ucan.c
+++ b/drivers/net/can/usb/ucan.c
@@ -1534,9 +1534,8 @@ static int ucan_probe(struct usb_interface *intf,
 				     sizeof(union ucan_ctl_payload));
 	if (ret > 0) {
 		/* copy string while ensuring zero termination */
-		strncpy(firmware_str, up->ctl_msg_buffer->raw,
-			sizeof(union ucan_ctl_payload));
-		firmware_str[sizeof(union ucan_ctl_payload)] = '\0';
+		strscpy(firmware_str, up->ctl_msg_buffer->raw,
+			sizeof(union ucan_ctl_payload) + 1);
 	} else {
 		strcpy(firmware_str, "unknown");
 	}
-- 
2.15.2

             reply	other threads:[~2022-12-07  1:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-07  1:09 yang.yang29 [this message]
2022-12-07  9:28 ` [PATCH linux-next] can: ucan: use strscpy() to instead of strncpy() Marc Kleine-Budde

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=202212070909095189693@zte.com.cn \
    --to=yang.yang29@zte.com.cn \
    --cc=davem@davemloft.net \
    --cc=dzm91@hust.edu.cn \
    --cc=edumazet@google.com \
    --cc=gustavoars@kernel.org \
    --cc=julia.lawall@inria.fr \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=socketcan@hartkopp.net \
    --cc=stefan.maetje@esd.eu \
    --cc=wg@grandegger.com \
    --cc=xu.panda@zte.com.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;
as well as URLs for NNTP newsgroup(s).