[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCHv2 13/22] virtio-9p: avoid unwarranted uses of strncp
From: |
Jim Meyering |
Subject: |
[Qemu-devel] [PATCHv2 13/22] virtio-9p: avoid unwarranted uses of strncpy |
Date: |
Wed, 30 May 2012 09:46:32 +0200 |
From: Jim Meyering <address@hidden>
In all of these cases, the uses of strncpy were unnecessary, since
at each point of use we know that the NUL-terminated source bytes
fit in the destination buffer. Use memcpy in place of strncpy.
Acked-by: Aneesh Kumar K.V <address@hidden>
Signed-off-by: Jim Meyering <address@hidden>
---
hw/9pfs/virtio-9p-posix-acl.c | 6 ++++--
hw/9pfs/virtio-9p-xattr-user.c | 3 ++-
hw/9pfs/virtio-9p-xattr.c | 3 ++-
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/hw/9pfs/virtio-9p-posix-acl.c b/hw/9pfs/virtio-9p-posix-acl.c
index a1948e3..c064017 100644
--- a/hw/9pfs/virtio-9p-posix-acl.c
+++ b/hw/9pfs/virtio-9p-posix-acl.c
@@ -44,7 +44,8 @@ static ssize_t mp_pacl_listxattr(FsContext *ctx, const char
*path,
return -1;
}
- strncpy(value, ACL_ACCESS, len);
+ /* len includes the trailing NUL */
+ memcpy(value, ACL_ACCESS, len);
return 0;
}
@@ -95,7 +96,8 @@ static ssize_t mp_dacl_listxattr(FsContext *ctx, const char
*path,
return -1;
}
- strncpy(value, ACL_DEFAULT, len);
+ /* len includes the trailing NUL */
+ memcpy(value, ACL_ACCESS, len);
return 0;
}
diff --git a/hw/9pfs/virtio-9p-xattr-user.c b/hw/9pfs/virtio-9p-xattr-user.c
index 5044a3e..5bb6020 100644
--- a/hw/9pfs/virtio-9p-xattr-user.c
+++ b/hw/9pfs/virtio-9p-xattr-user.c
@@ -61,7 +61,8 @@ static ssize_t mp_user_listxattr(FsContext *ctx, const char
*path,
return -1;
}
- strncpy(value, name, name_size);
+ /* name_size includes the trailing NUL. */
+ memcpy(value, name, name_size);
return name_size;
}
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;
}
--
1.7.10.2.605.gbefc5ed
- [Qemu-devel] [PATCHv2 01/22] scsi, pci, qdev, isa-bus, sysbus: don't let *_get_fw_dev_path return NULL, (continued)
- [Qemu-devel] [PATCHv2 01/22] scsi, pci, qdev, isa-bus, sysbus: don't let *_get_fw_dev_path return NULL, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 07/22] lm32: avoid buffer overrun, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 02/22] sparc: use g_strdup in place of unchecked strdup, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 04/22] sheepdog: avoid a few buffer overruns, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 05/22] vmdk: relative_path: use pstrcpy in place of strncpy, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 08/22] os-posix: avoid buffer overrun, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 06/22] hw/9pfs: avoid buffer overrun, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 10/22] linux-user: remove two unchecked uses of strdup, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 16/22] qemu-ga: prefer pstrcpy: consistently NUL-terminate ifreq.ifr_name, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 12/22] bt: replace fragile snprintf use and unwarranted strncpy, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 13/22] virtio-9p: avoid unwarranted uses of strncpy,
Jim Meyering <=
- [Qemu-devel] [PATCHv2 09/22] ppc: avoid buffer overrun: use pstrcpy, not strncpy, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 11/22] ui/vnc: simplify and avoid strncpy, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 19/22] qcow2: mark this file's sole strncpy use as justified, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 14/22] vscsi: avoid unwarranted strncpy, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 17/22] libcacard/vcard_emul_nss: use pstrcpy in place of strncpy, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 22/22] doc: update HACKING wrt strncpy/pstrcpy, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 21/22] scsi: mark an strncpy use as valid, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 18/22] acpi: remove strzcpy (strncpy-identical) function; just use strncpy, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 20/22] hw/r2d: add comment: this strncpy use is ok, Jim Meyering, 2012/05/30
- [Qemu-devel] [PATCHv2 15/22] target-i386: use pstrcpy, not strncpy, Jim Meyering, 2012/05/30