[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCHv2 22/22] doc: update HACKING wrt strncpy/pstrcpy
From: |
Jim Meyering |
Subject: |
[Qemu-devel] [PATCHv2 22/22] doc: update HACKING wrt strncpy/pstrcpy |
Date: |
Wed, 30 May 2012 09:46:41 +0200 |
From: Jim Meyering <address@hidden>
Reword the section on strncpy: its NUL-filling is important
in some cases. Mention that pstrcpy's signature is different.
Signed-off-by: Jim Meyering <address@hidden>
---
HACKING | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/HACKING b/HACKING
index 471cf1d..dddd617 100644
--- a/HACKING
+++ b/HACKING
@@ -91,10 +91,11 @@ emulators.
4. String manipulation
-Do not use the strncpy function. According to the man page, it does
-*not* guarantee a NULL-terminated buffer, which makes it extremely dangerous
-to use. Instead, use functionally equivalent function:
-void pstrcpy(char *buf, int buf_size, const char *str)
+Do not use the strncpy function. As mentioned in the man page, it does *not*
+guarantee a NULL-terminated buffer, which makes it extremely dangerous to use.
+It also zeros trailing destination bytes out to the specified length. Instead,
+use this similar function when possible, but note its different signature:
+void pstrcpy(char *dest, int dest_buf_size, const char *src)
Don't use strcat because it can't check for buffer overflows, but:
char *pstrcat(char *buf, int buf_size, const char *s)
--
1.7.10.2.605.gbefc5ed
- [Qemu-devel] [PATCHv2 06/22] hw/9pfs: avoid buffer overrun, (continued)
- [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, 2012/05/30
- [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 <=
- [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