s390/zcrypt: use strscpy() to instead of strncpy()
authorXu Panda <xu.panda@zte.com.cn>
Thu, 5 Jan 2023 12:24:34 +0000 (20:24 +0800)
committerHeiko Carstens <hca@linux.ibm.com>
Mon, 9 Jan 2023 13:34:09 +0000 (14:34 +0100)
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.cn>
Link: https://lore.kernel.org/r/202301052024349365834@zte.com.cn
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
drivers/s390/crypto/zcrypt_api.c

index 4bf36e5..6fe05bb 100644 (file)
@@ -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));