Skip to content

Commit

Permalink
xfs: use strscpy() to instead of strncpy()
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
  • Loading branch information
Xu Panda authored and Darrick J. Wong committed Feb 5, 2023
1 parent 6d796c5 commit 8954c44
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions fs/xfs/xfs_xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8954c44

Please sign in to comment.