Patchwork [13/22] virtio-9p: avoid unwarranted use of strncpy

login
register
mail settings
Submitter Jim Meyering
Date May 9, 2012, 9:23 a.m.
Message ID <1336555446-20180-14-git-send-email-jim@meyering.net>
Download mbox | patch
Permalink /patch/157979/
State New
Headers show

Comments

Jim Meyering - May 9, 2012, 9:23 a.m.
From: Jim Meyering <meyering@redhat.com>

The use of strncpy in pt_listxattr is unnecessary, since we
know that the NUL-terminated source bytes fit in the destination
buffer.  Use memcpy in place of strncpy.

Signed-off-by: Jim Meyering <meyering@redhat.com>
---
 hw/9pfs/virtio-9p-xattr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch

diff --git a/hw/9pfs/virtio-9p-xattr.c b/hw/9pfs/virtio-9p-xattr.c
index 7f08f6e..a839606 100644
--- a/hw/9pfs/virtio-9p-xattr.c
+++ b/hw/9pfs/virtio-9p-xattr.c
@@ -53,7 +53,8 @@  ssize_t pt_listxattr(FsContext *ctx, const char *path,
         return -1;
     }

-    strncpy(value, name, name_size);
+    /* no need for strncpy: name_size is strlen(name)+1 */
+    memcpy(value, name, name_size);
     return name_size;
 }