]> Git Repo - linux.git/commitdiff
xfs: use strscpy() to instead of strncpy()
authorXu Panda <[email protected]>
Wed, 1 Feb 2023 17:31:34 +0000 (09:31 -0800)
committerDarrick J. Wong <[email protected]>
Sun, 5 Feb 2023 16:48:11 +0000 (08:48 -0800)
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]>
fs/xfs/xfs_xattr.c

index 10aa1fd39d2b0354a2cafa2d38a8d86591893a49..913c1794bc2f9248525ec143f7c603275b062bdd 100644 (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;
This page took 0.058863 seconds and 4 git commands to generate.