xfs: use strscpy() to instead of strncpy()

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 <[email protected]>
Signed-off-by: Yang Yang <[email protected]>
Reviewed-by: Darrick J. Wong <[email protected]>
Signed-off-by: Darrick J. Wong <[email protected]>
This commit is contained in:
Xu Panda
2023-02-05 08:48:11 -08:00
committed by Darrick J. Wong
parent 6d796c50f8
commit 8954c44ff4
+1 -3
View File
@@ -212,9 +212,7 @@ __xfs_xattr_put_listent(
offset = context->buffer + context->count;
memcpy(offset, prefix, prefix_len);
offset += prefix_len;
strncpy(offset, (char *)name, namelen); /* real name */
offset += namelen;
*offset = '\0';
strscpy(offset, (char *)name, namelen + 1); /* real name */
compute_size:
context->count += prefix_len + namelen + 1;