linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: tool: getstat: Fix unterminated strncpy
@ 2019-07-30  8:40 Chuhong Yuan
  2019-07-30 11:35 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Chuhong Yuan @ 2019-07-30  8:40 UTC (permalink / raw)
  Cc: Corentin Labbe, Herbert Xu, linux-kernel, Chuhong Yuan

strncpy(dest, src, strlen(src)) leads to unterminated
dest, which is dangerous.
Fix it by using strscpy.

Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
 tools/crypto/getstat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/crypto/getstat.c b/tools/crypto/getstat.c
index 9e8ff76420fa..554ba08d9652 100644
--- a/tools/crypto/getstat.c
+++ b/tools/crypto/getstat.c
@@ -41,7 +41,7 @@ static int get_stat(const char *drivername)
 	req.n.nlmsg_type = CRYPTO_MSG_GETSTAT;
 	req.n.nlmsg_seq = time(NULL);
 
-	strncpy(req.cru.cru_driver_name, drivername, strlen(drivername));
+	strscpy(req.cru.cru_driver_name, drivername, strlen(drivername) + 1);
 
 	sd =  socket(AF_NETLINK, SOCK_RAW, NETLINK_CRYPTO);
 	if (sd < 0) {
-- 
2.20.1


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

* Re: [PATCH] crypto: tool: getstat: Fix unterminated strncpy
  2019-07-30  8:40 [PATCH] crypto: tool: getstat: Fix unterminated strncpy Chuhong Yuan
@ 2019-07-30 11:35 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2019-07-30 11:35 UTC (permalink / raw)
  To: Chuhong Yuan; +Cc: Corentin Labbe, linux-kernel

On Tue, Jul 30, 2019 at 04:40:18PM +0800, Chuhong Yuan wrote:
> strncpy(dest, src, strlen(src)) leads to unterminated
> dest, which is dangerous.
> Fix it by using strscpy.
> 
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> ---
>  tools/crypto/getstat.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

This file no longer exists in cryptodev.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2019-07-30 11:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-30  8:40 [PATCH] crypto: tool: getstat: Fix unterminated strncpy Chuhong Yuan
2019-07-30 11:35 ` Herbert Xu

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).