public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH linux-next v2] s390/zcrypt: use strscpy() to instead of strncpy()
@ 2023-01-03  2:02 yang.yang29
  2023-01-03  9:51 ` Heiko Carstens
  0 siblings, 1 reply; 4+ messages in thread
From: yang.yang29 @ 2023-01-03  2:02 UTC (permalink / raw)
  To: freude, hca
  Cc: gor, agordeev, borntraeger, svens, linux-s390, linux-kernel,
	xu.panda, yang.yang29

From: Yang Yang <yang.yang29@zte.com>

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

Signed-off-by: Yang Yang <yang.yang29@zte.com>
Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
---
chang for v2
 - match the FROM with the Email
---
 drivers/s390/crypto/zcrypt_api.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index 4bf36e53fe3e..6fe05bb82c77 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -347,8 +347,7 @@ static ssize_t zcdn_create_store(struct class *class,
 	int rc;
 	char name[ZCDN_MAX_NAME];

-	strncpy(name, skip_spaces(buf), sizeof(name));
-	name[sizeof(name) - 1] = '\0';
+	strscpy(name, skip_spaces(buf), sizeof(name));

 	rc = zcdn_create(strim(name));

@@ -365,8 +364,7 @@ static ssize_t zcdn_destroy_store(struct class *class,
 	int rc;
 	char name[ZCDN_MAX_NAME];

-	strncpy(name, skip_spaces(buf), sizeof(name));
-	name[sizeof(name) - 1] = '\0';
+	strscpy(name, skip_spaces(buf), sizeof(name));

 	rc = zcdn_destroy(strim(name));

-- 
2.15.2

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

end of thread, other threads:[~2023-01-10  3:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-03  2:02 [PATCH linux-next v2] s390/zcrypt: use strscpy() to instead of strncpy() yang.yang29
2023-01-03  9:51 ` Heiko Carstens
2023-01-05 14:01   ` Bagas Sanjaya
2023-01-10  3:16     ` yang.yang29

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