public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH linux-next] rpmsg: use strscpy() to instead of strncpy()
@ 2022-12-23  2:44 yang.yang29
  2023-01-05 21:04 ` Mathieu Poirier
  0 siblings, 1 reply; 2+ messages in thread
From: yang.yang29 @ 2022-12-23  2:44 UTC (permalink / raw)
  To: andersson
  Cc: mathieu.poirier, linux-remoteproc, linux-kernel, xu.panda,
	yang.yang29

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/rpmsg/rpmsg_ns.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/rpmsg/rpmsg_ns.c b/drivers/rpmsg/rpmsg_ns.c
index c70ad03ff2e9..c7b5b60aef4d 100644
--- a/drivers/rpmsg/rpmsg_ns.c
+++ b/drivers/rpmsg/rpmsg_ns.c
@@ -48,9 +48,7 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
 	}

 	/* don't trust the remote processor for null terminating the name */
-	msg->name[RPMSG_NAME_SIZE - 1] = '\0';
-
-	strncpy(chinfo.name, msg->name, sizeof(chinfo.name));
+	strscpy(chinfo.name, msg->name, sizeof(chinfo.name));
 	chinfo.src = RPMSG_ADDR_ANY;
 	chinfo.dst = rpmsg32_to_cpu(rpdev, msg->addr);

-- 
2.15.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH linux-next] rpmsg: use strscpy() to instead of strncpy()
  2022-12-23  2:44 [PATCH linux-next] rpmsg: use strscpy() to instead of strncpy() yang.yang29
@ 2023-01-05 21:04 ` Mathieu Poirier
  0 siblings, 0 replies; 2+ messages in thread
From: Mathieu Poirier @ 2023-01-05 21:04 UTC (permalink / raw)
  To: yang.yang29; +Cc: andersson, linux-remoteproc, linux-kernel, xu.panda

On Fri, Dec 23, 2022 at 10:44:10AM +0800, yang.yang29@zte.com.cn wrote:
> 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/rpmsg/rpmsg_ns.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/rpmsg/rpmsg_ns.c b/drivers/rpmsg/rpmsg_ns.c
> index c70ad03ff2e9..c7b5b60aef4d 100644
> --- a/drivers/rpmsg/rpmsg_ns.c
> +++ b/drivers/rpmsg/rpmsg_ns.c
> @@ -48,9 +48,7 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
>  	}
> 
>  	/* don't trust the remote processor for null terminating the name */
> -	msg->name[RPMSG_NAME_SIZE - 1] = '\0';
> -

This is broken.

> -	strncpy(chinfo.name, msg->name, sizeof(chinfo.name));
> +	strscpy(chinfo.name, msg->name, sizeof(chinfo.name));

In this case there isn't a need to use strscpy() since we _know_ from the above
that msg->name is NULL terminated.

>  	chinfo.src = RPMSG_ADDR_ANY;
>  	chinfo.dst = rpmsg32_to_cpu(rpdev, msg->addr);
> 
> -- 
> 2.15.2

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-05 21:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-23  2:44 [PATCH linux-next] rpmsg: use strscpy() to instead of strncpy() yang.yang29
2023-01-05 21:04 ` Mathieu Poirier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox