[Qemu-devel] [PATCHv3 19/20] hw/r2d: add comment: this strncpy use is ok

2012-10-04 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- hw/r2d.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/r2d.c b/hw/r2d.c index 0f16e81..1bc191f 100644 --- a/hw/r2d.c +++ b/hw/r2d.c @@ -332,6 +332,8 @@ static void r2d_init(ram_addr_t ram_size, } if (kernel_cmdline

[Qemu-devel] [PATCHv3 04/20] sheepdog: avoid a few buffer overruns

2012-10-04 Thread Jim Meyering
From: Jim Meyering * parse_vdiname: Use pstrcpy, not strncpy, when the destination buffer must be NUL-terminated. * sd_open: Likewise, avoid buffer overrun. * do_sd_create: Likewise. Leave the preceding memset, since pstrcpy does not NUL-fill, and filename needs that. * sd_snapshot_create: Add

[Qemu-devel] [PATCHv3 08/20] os-posix: avoid buffer overrun

2012-10-04 Thread Jim Meyering
From: Jim Meyering os_set_proc_name: Use pstrcpy, in place of strncpy and the ineffectual preceding assignment: name[sizeof(name) - 1] = 0; Signed-off-by: Jim Meyering --- os-posix.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/os-posix.c b/os-posix.c index eabccb8

[Qemu-devel] [PATCHv3 20/20] doc: update HACKING wrt strncpy/pstrcpy

2012-10-04 Thread Jim Meyering
From: Jim Meyering 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 --- HACKING | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/HACKING b/HACKING index 47

[Qemu-devel] [PATCHv3 01/20] scsi, pci, qdev, isa-bus, sysbus: don't let *_get_fw_dev_path return NULL

2012-10-04 Thread Jim Meyering
From: Jim Meyering Use g_strdup rather than strdup, because the sole caller (qdev_get_fw_dev_path_helper) assumes it gets non-NULL, and dereferences it. Besides, in that caller, the allocated buffer is already freed with g_free, so it's better to allocate with a matching g_strdup. In one

[Qemu-devel] [PATCHv3 05/20] vmdk: relative_path: use pstrcpy in place of strncpy

2012-10-04 Thread Jim Meyering
From: Jim Meyering Avoid strncpy+manual-NUL-terminate. Use pstrcpy instead. Acked-by: Kevin Wolf Signed-off-by: Jim Meyering --- block/vmdk.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index f2e861b..1a80e5a 100644 --- a/block/vmdk.c

[Qemu-devel] [PATCHv3 09/20] ppc: avoid buffer overrun: use pstrcpy, not strncpy

2012-10-04 Thread Jim Meyering
From: Jim Meyering A terminal NUL is required by caller's use of strchr. It's better not to use strncpy at all, since there is no need to zero out hundreds of trailing bytes for each iteration. Signed-off-by: Jim Meyering --- target-ppc/kvm.c | 2 +- 1 file changed, 1 insertion(+),

[Qemu-devel] [PATCHv3 00/20] strncpy: best avoided

2012-10-04 Thread Jim Meyering
From: Jim Meyering I included a quick classification of these change sets for the original series, (see https://lists.gnu.org/archive/html/qemu-devel/2012-05/msg01151.html) rebased in late May but perhaps the release-related timing was off. I've rebased one last time to prepare this v3 s

[Qemu-devel] [PATCHv3 10/20] linux-user: remove two unchecked uses of strdup

2012-10-04 Thread Jim Meyering
From: Jim Meyering Remove two uses of strdup (use g_path_get_basename instead), and add a comment that this strncpy use is ok. Reviewed-by: Peter Maydell Signed-off-by: Jim Meyering --- linux-user/elfload.c | 12 +++- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a

[Qemu-devel] [PATCHv3 02/20] sparc: use g_strdup in place of unchecked strdup

2012-10-04 Thread Jim Meyering
From: Jim Meyering This avoids a NULL-deref upon strdup failure. Also update matching free to g_free. Signed-off-by: Jim Meyering --- target-sparc/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target-sparc/cpu.c b/target-sparc/cpu.c index f7c004c..eb9f0e7

[Qemu-devel] [PATCHv3 12/20] bt: replace fragile snprintf use and unwarranted strncpy

2012-10-04 Thread Jim Meyering
From: Jim Meyering In bt_hci_name_req a failed snprintf could return len larger than sizeof(params.name), which means the following memset call would have a "length" value of (size_t)-1, -2, etc... Sounds scary. But currently, one can deduce that there is no problem: strlen(slave->

[Qemu-devel] [PATCHv3 16/20] libcacard/vcard_emul_nss: use pstrcpy in place of strncpy

2012-10-04 Thread Jim Meyering
From: Jim Meyering Replace strncpy+NUL-terminate use with use of pstrcpy. This requires linking with cutils.o (or else vssclient doesn't link), so add that in the Makefile. Acked-by: Alon Levy Signed-off-by: Jim Meyering --- libcacard/Makefile | 3 +++ libcacard/vcard_emul_nss.

Re: [Qemu-devel] [PATCHv3 11/20] ui/vnc: simplify and avoid strncpy

2012-10-04 Thread Jim Meyering
Peter Maydell wrote: > On 4 October 2012 12:09, Jim Meyering wrote: >> From: Jim Meyering >> >> Don't bother with strncpy. There's no need for its zero-fill. >> Use g_strndup in place of g_malloc+strncpy+NUL-terminate. >> >> Signed-off-by

[Qemu-devel] [PATCHv3 13/20] virtio-9p: avoid unwarranted uses of strncpy

2012-10-04 Thread Jim Meyering
From: Jim Meyering 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 Signed-off-by: Jim Meyering --- hw/9pfs/virtio-9p

[Qemu-devel] [PATCHv3 17/20] acpi: remove strzcpy (strncpy-identical) function; just use strncpy

2012-10-04 Thread Jim Meyering
From: Jim Meyering Adjust all uses s/strzcpy/strncpy/ and mark these uses of strncpy as "ok". Signed-off-by: Jim Meyering --- hw/acpi.c | 24 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/hw/acpi.c b/hw/acpi.c index f7950be..f4aca49 10064

[Qemu-devel] [PATCHv3 14/20] vscsi: avoid unwarranted strncpy

2012-10-04 Thread Jim Meyering
From: Jim Meyering Don't use strncpy when the source string is known to fit in the destination buffer. Use equivalent memcpy. We could even use strcpy, here, but some static analyzers warn about that, so don't add new uses. Acked-by: David Gibson Signed-off-by: Jim Meyerin

[Qemu-devel] [PATCHv3 15/20] qemu-ga: prefer pstrcpy: consistently NUL-terminate ifreq.ifr_name

2012-10-04 Thread Jim Meyering
From: Jim Meyering NUL-termination of the .ifr_name field is not required, but is fine (and preferable to using strncpy and leaving the reader to wonder), since the first thing the linux kernel does is to clear the last byte. Besides, using pstrcpy here makes this setting of ifr_name consistent

[Qemu-devel] [PATCHv3 18/20] qcow2: mark this file's sole strncpy use as justified

2012-10-04 Thread Jim Meyering
From: Jim Meyering Acked-by: Kevin Wolf Signed-off-by: Jim Meyering --- block/qcow2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/qcow2.c b/block/qcow2.c index aa5e603..c1ff31f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1096,6 +1096,7 @@ int qcow2_update_header

[Qemu-devel] [PATCHv3 06/20] hw/9pfs: avoid buffer overrun

2012-10-04 Thread Jim Meyering
From: Jim Meyering v9fs_add_dir_node and qemu_v9fs_synth_add_file used strncpy to form node->name, which requires NUL-termination, but strncpy does not ensure NUL-termination. Use pstrcpy, which does. Acked-by: Aneesh Kumar K.V Signed-off-by: Jim Meyering --- hw/9pfs/virtio-9p-synth.c

[Qemu-devel] [PATCHv3 11/20] ui/vnc: simplify and avoid strncpy

2012-10-04 Thread Jim Meyering
From: Jim Meyering Don't bother with strncpy. There's no need for its zero-fill. Use g_strndup in place of g_malloc+strncpy+NUL-terminate. Signed-off-by: Jim Meyering --- ui/vnc-auth-sasl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ui/vnc-auth-sasl.

[Qemu-devel] [PATCHv3 03/20] block: avoid buffer overrun by using pstrcpy, not strncpy

2012-10-04 Thread Jim Meyering
From: Jim Meyering Also, use PATH_MAX, rather than the arbitrary 1024. Using PATH_MAX is more consistent with other filename-related variables in this file, like backing_filename and tmp_filename. Acked-by: Kevin Wolf Signed-off-by: Jim Meyering --- block.c | 5 +++-- 1 file changed, 3

[Qemu-devel] [PATCHv3 07/20] lm32: avoid buffer overrun

2012-10-04 Thread Jim Meyering
From: Jim Meyering Actually do what the comment says, using pstrcpy NUL-terminate: strncpy does not always do that. Signed-off-by: Jim Meyering --- hw/lm32_hwsetup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/lm32_hwsetup.h b/hw/lm32_hwsetup.h index 8fc285e

[Qemu-devel] [PATCHv3 5/5] softmmu-semi: fix lock_user* functions not to deref NULL upon OOM

2012-08-22 Thread Jim Meyering
From: Jim Meyering Return NULL upon malloc failure. Signed-off-by: Jim Meyering --- softmmu-semi.h | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/softmmu-semi.h b/softmmu-semi.h index 648cb95..bcb979a 100644 --- a/softmmu-semi.h +++ b/softmmu-semi.h @@ -40,7 +40,7

[Qemu-devel] [PATCHv3 3/5] sheepdog: don't leak socket file descriptor upon connection failure

2012-08-22 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- block/sheepdog.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/sheepdog.c b/block/sheepdog.c index a04ad99..df4f441 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -485,6 +485,7 @@ static int connect_to_sdog(const char

[Qemu-devel] [PATCHv3 4/5] arm-semi: don't leak 1KB user string lock buffer upon TARGET_SYS_OPEN

2012-08-22 Thread Jim Meyering
From: Jim Meyering Always call unlock_user before returning. Signed-off-by: Jim Meyering --- target-arm/arm-semi.c | 13 +++-- 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/target-arm/arm-semi.c b/target-arm/arm-semi.c index 2495206..73bde58 100644 --- a/target-arm/arm

[Qemu-devel] [PATCHv3 0/5] plug memory and file-descriptor leaks

2012-08-22 Thread Jim Meyering
From: Jim Meyering Hi Anthony, I posted this series back in May, got some good feedback leading to a pair of v2 patches. Since then one of the 6 patches was applied. I'm calling this v3, but it is merely a trivial rebase of the v1 and v2 patches. Hoping it's not too late for 1.2, he

[Qemu-devel] [PATCHv3 2/5] linux-user: do_msgrcv: don't leak host_mb upon TARGET_EFAULT failure

2012-08-22 Thread Jim Meyering
From: Jim Meyering Also, use g_malloc to avoid NULL-deref upon OOM. Signed-off-by: Jim Meyering --- linux-user/syscall.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 41c869b..1174306 100644 --- a/linux-user/syscall.c

[Qemu-devel] [PATCHv3 1/5] qemu-ga: don't leak a file descriptor upon failed lockf

2012-08-22 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- qemu-ga.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qemu-ga.c b/qemu-ga.c index 8f87621..26671fe 100644 --- a/qemu-ga.c +++ b/qemu-ga.c @@ -247,6 +247,9 @@ static bool ga_open_pidfile(const char *pidfile) pidfd = open

Re: [Qemu-devel] [PATCHv3 2/2] envlist.c: handle strdup failure

2012-08-17 Thread Jim Meyering
Andreas Färber wrote: > Am 22.05.2012 12:16, schrieb Jim Meyering: >> From: Jim Meyering >> >> Without this, envlist_to_environ may silently fail to copy all >> strings into the destination buffer, and both callers would leak >> any env strings allocated af

[Qemu-devel] [PATCHv4 2/2] envlist.c: handle strdup failure

2012-08-17 Thread Jim Meyering
From: Jim Meyering Without this, envlist_to_environ may silently fail to copy all strings into the destination buffer, and both callers would leak any env strings allocated after a failing strdup, because the freeing code stops at the first NULL pointer. Signed-off-by: Jim Meyering

[Qemu-devel] [PATCHv4 1/2] envlist.c: conform to QEMU's coding style

2012-08-17 Thread Jim Meyering
From: Jim Meyering Convert each TAB(width-4) to equivalent spaces. Put braces around each one-line if-body. Signed-off-by: Jim Meyering --- envlist.c | 268 -- 1 file changed, 140 insertions(+), 128 deletions(-) diff --git a

[Qemu-devel] [PATCHv4 0/2] envlist.c: handle strdup failure

2012-08-17 Thread Jim Meyering
From: Jim Meyering Differences from v3 (no semantic change): - change 1/2 so this file conforms more closely to QEMU's coding style, by adding braces around each one-line if body (there was no one-line else- or while-block). - move an indentation correction from 2/2 into 1/2

Re: [Qemu-devel] [PATCHv2 2/2] envlist.c: handle strdup failure

2012-08-17 Thread Jim Meyering
Andreas Färber wrote: > Am 17.08.2012 15:35, schrieb Jim Meyering: >> Jim Meyering wrote: >>> From: Jim Meyering >>> >>> Without this, envlist_to_environ may silently fail to copy all >>> strings into the destination buffer, and both callers wou

Re: [Qemu-devel] [PATCH 4/6] sheepdog: don't leak socket file descriptor upon connection failure

2012-08-17 Thread Jim Meyering
Kevin Wolf wrote: > Am 17.08.2012 15:30, schrieb Jim Meyering: >> Kevin Wolf wrote: >>> Am 16.05.2012 15:07, schrieb Jim Meyering: >>>> From: Jim Meyering >>>> >>>> Signed-off-by: Jim Meyering >>> >>> Acked-by: Kevin

Re: [Qemu-devel] [PATCH 0/9] convert many more globals to "static"

2012-08-17 Thread Jim Meyering
Jim Meyering wrote: > From: Jim Meyering > > Following up on discussion here, > > http://marc.info/?t=13375948768&r=1&w=2 > > here are patches to limit the scope of the remaining global variables. > Most changes simply added a preceding "static".

Re: [Qemu-devel] [PATCHv2 2/2] envlist.c: handle strdup failure

2012-08-17 Thread Jim Meyering
Jim Meyering wrote: > From: Jim Meyering > > Without this, envlist_to_environ may silently fail to copy all > strings into the destination buffer, and both callers would leak > any env strings allocated after a failing strdup, because the > freeing code stops at the first NULL p

Re: [Qemu-devel] [PATCH 4/6] sheepdog: don't leak socket file descriptor upon connection failure

2012-08-17 Thread Jim Meyering
Kevin Wolf wrote: > Am 16.05.2012 15:07, schrieb Jim Meyering: >> From: Jim Meyering >> >> Signed-off-by: Jim Meyering > > Acked-by: Kevin Wolf Hi Kevin, AFAICS, only one of these 6 patches has been applied. >From what I recall (it's been nearly 3mo), ther

Re: [Qemu-devel] [PATCHv2 03/22] block: avoid buffer overrun by using pstrcpy, not strncpy

2012-05-30 Thread Jim Meyering
Stefan Weil wrote: > Am 30.05.2012 09:46, schrieb Jim Meyering: >> From: Jim Meyering >> >> Also, use PATH_MAX, rather than the arbitrary 1024. >> Using PATH_MAX is more consistent with other filename-related >> variables in this file, like backing_filename and tm

[Qemu-devel] [PATCHv2 07/22] lm32: avoid buffer overrun

2012-05-30 Thread Jim Meyering
From: Jim Meyering Actually do what the comment says, using pstrcpy NUL-terminate: strncpy does not always do that. Signed-off-by: Jim Meyering --- hw/lm32_hwsetup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/lm32_hwsetup.h b/hw/lm32_hwsetup.h index 8fc285e

[Qemu-devel] [PATCHv2 00/22] strncpy: best avoided

2012-05-30 Thread Jim Meyering
From: Jim Meyering Given qemu's HACKING comments, I'm sure many here have read "man strncpy", where it indicates it is often not the best function to use. However, many of the uses of strncpy in qemu mistakenly fail to ensure that the destination buffer is NUL-terminated.

[Qemu-devel] [PATCHv2 05/22] vmdk: relative_path: use pstrcpy in place of strncpy

2012-05-30 Thread Jim Meyering
From: Jim Meyering Avoid strncpy+manual-NUL-terminate. Use pstrcpy instead. Acked-by: Kevin Wolf Signed-off-by: Jim Meyering --- block/vmdk.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 18e9b4c..bfd7357 100644 --- a/block/vmdk.c

[Qemu-devel] [PATCHv2 17/22] libcacard/vcard_emul_nss: use pstrcpy in place of strncpy

2012-05-30 Thread Jim Meyering
From: Jim Meyering Replace strncpy+NUL-terminate use with use of pstrcpy. This requires linking with cutils.o (or else vssclient doesn't link), so add that in the Makefile. Acked-by: Alon Levy Signed-off-by: Jim Meyering --- libcacard/Makefile | 2 +- libcacard/vcard_emul_nss.

[Qemu-devel] [PATCHv2 10/22] linux-user: remove two unchecked uses of strdup

2012-05-30 Thread Jim Meyering
From: Jim Meyering Remove two uses of strdup (use g_path_get_basename instead), and add a comment that this strncpy use is ok. Reviewed-by: Peter Maydell Signed-off-by: Jim Meyering --- linux-user/elfload.c | 12 +++- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a

[Qemu-devel] [PATCHv2 18/22] acpi: remove strzcpy (strncpy-identical) function; just use strncpy

2012-05-30 Thread Jim Meyering
From: Jim Meyering Adjust all uses s/strzcpy/strncpy/ and mark these uses of strncpy as "ok". Signed-off-by: Jim Meyering --- hw/acpi.c | 24 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/hw/acpi.c b/hw/acpi.c index 5d521e5..45ab345 10064

[Qemu-devel] [PATCHv2 21/22] scsi: mark an strncpy use as valid

2012-05-30 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- hw/scsi-bus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 3edda28..98170c3 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -406,6 +406,7 @@ static bool scsi_target_emulate_inquiry(SCSITargetReq *r

[Qemu-devel] [PATCHv2 11/22] ui/vnc: simplify and avoid strncpy

2012-05-30 Thread Jim Meyering
From: Jim Meyering Don't bother with strncpy. There's no need for its zero-fill. Use g_strndup in place of g_malloc+strncpy+NUL-terminate. Signed-off-by: Jim Meyering --- ui/vnc-auth-sasl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ui/vnc-auth-sasl.

[Qemu-devel] [PATCHv2 15/22] target-i386: use pstrcpy, not strncpy

2012-05-30 Thread Jim Meyering
From: Jim Meyering Use pstrcpy rather than strncpy in one more case (in cpudef_setfield). This makes our handling of ->model_id consistent with another pstrcpy-vs-model_id use below. Signed-off-by: Jim Meyering --- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) d

[Qemu-devel] [PATCHv2 08/22] os-posix: avoid buffer overrun

2012-05-30 Thread Jim Meyering
From: Jim Meyering os_set_proc_name: Use pstrcpy, in place of strncpy and the ineffectual preceding assignment: name[sizeof(name) - 1] = 0; Signed-off-by: Jim Meyering --- os-posix.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/os-posix.c b/os-posix.c index daf3d6f

[Qemu-devel] [PATCHv2 22/22] doc: update HACKING wrt strncpy/pstrcpy

2012-05-30 Thread Jim Meyering
From: Jim Meyering 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 --- HACKING | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/HACKING b/HACKING index 47

[Qemu-devel] [PATCHv2 06/22] hw/9pfs: avoid buffer overrun

2012-05-30 Thread Jim Meyering
From: Jim Meyering v9fs_add_dir_node and qemu_v9fs_synth_add_file used strncpy to form node->name, which requires NUL-termination, but strncpy does not ensure NUL-termination. Use pstrcpy, which does. Acked-by: Aneesh Kumar K.V Signed-off-by: Jim Meyering --- hw/9pfs/virtio-9p-synth.c

[Qemu-devel] [PATCHv2 19/22] qcow2: mark this file's sole strncpy use as justified

2012-05-30 Thread Jim Meyering
From: Jim Meyering Acked-by: Kevin Wolf Signed-off-by: Jim Meyering --- block/qcow2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/qcow2.c b/block/qcow2.c index c2e49cd..6d34f1a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -994,6 +994,7 @@ int qcow2_update_header

[Qemu-devel] [PATCHv2 01/22] scsi, pci, qdev, isa-bus, sysbus: don't let *_get_fw_dev_path return NULL

2012-05-30 Thread Jim Meyering
From: Jim Meyering Use g_strdup rather than strdup, because the sole caller (qdev_get_fw_dev_path_helper) assumes it gets non-NULL, and dereferences it. Besides, in that caller, the allocated buffer is already freed with g_free, so it's better to allocate with a matching g_strdup. In one

[Qemu-devel] [PATCHv2 04/22] sheepdog: avoid a few buffer overruns

2012-05-30 Thread Jim Meyering
From: Jim Meyering * parse_vdiname: Use pstrcpy, not strncpy, when the destination buffer must be NUL-terminated. * sd_open: Likewise, avoid buffer overrun. * do_sd_create: Likewise. Leave the preceding memset, since pstrcpy does not NUL-fill, and filename needs that. * sd_snapshot_create: Add

[Qemu-devel] [PATCHv2 16/22] qemu-ga: prefer pstrcpy: consistently NUL-terminate ifreq.ifr_name

2012-05-30 Thread Jim Meyering
From: Jim Meyering NUL-termination of the .ifr_name field is not required, but is fine (and preferable to using strncpy and leaving the reader to wonder), since the first thing the linux kernel does is to clear the last byte. Besides, using pstrcpy here makes this setting of ifr_name consistent

[Qemu-devel] [PATCHv2 13/22] virtio-9p: avoid unwarranted uses of strncpy

2012-05-30 Thread Jim Meyering
From: Jim Meyering 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 Signed-off-by: Jim Meyering --- hw/9pfs/virtio-9p

[Qemu-devel] [PATCHv2 14/22] vscsi: avoid unwarranted strncpy

2012-05-30 Thread Jim Meyering
From: Jim Meyering Don't use strncpy when the source string is known to fit in the destination buffer. Use equivalent memcpy. We could even use strcpy, here, but some static analyzers warn about that, so don't add new uses. Acked-by: David Gibson Signed-off-by: Jim Meyerin

[Qemu-devel] [PATCHv2 12/22] bt: replace fragile snprintf use and unwarranted strncpy

2012-05-30 Thread Jim Meyering
From: Jim Meyering In bt_hci_name_req a failed snprintf could return len larger than sizeof(params.name), which means the following memset call would have a "length" value of (size_t)-1, -2, etc... Sounds scary. But currently, one can deduce that there is no problem: strlen(slave->

[Qemu-devel] [PATCHv2 02/22] sparc: use g_strdup in place of unchecked strdup

2012-05-30 Thread Jim Meyering
From: Jim Meyering This avoids a NULL-deref upon strdup failure. Also update matching free to g_free. Signed-off-by: Jim Meyering --- target-sparc/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target-sparc/cpu.c b/target-sparc/cpu.c index 7ac6bdb..1e31318

[Qemu-devel] [PATCHv2 09/22] ppc: avoid buffer overrun: use pstrcpy, not strncpy

2012-05-30 Thread Jim Meyering
From: Jim Meyering A terminal NUL is required by caller's use of strchr. It's better not to use strncpy at all, since there is no need to zero out hundreds of trailing bytes for each iteration. Signed-off-by: Jim Meyering --- target-ppc/kvm.c | 2 +- 1 file changed, 1 insertion(+),

Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup

2012-05-30 Thread Jim Meyering
Anthony Liguori wrote: > On 05/30/2012 03:12 PM, Jim Meyering wrote: >> Anthony Liguori wrote: >>> On 05/09/2012 10:12 PM, Jim Meyering wrote: >>>> Peter Maydell wrote: >>>>> On 9 May 2012 15:01, Jim Meyering wrote: >>>>>>From 40

[Qemu-devel] [PATCHv2 20/22] hw/r2d: add comment: this strncpy use is ok

2012-05-30 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- hw/r2d.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/r2d.c b/hw/r2d.c index c55de01..ed841c5 100644 --- a/hw/r2d.c +++ b/hw/r2d.c @@ -328,6 +328,8 @@ static void r2d_init(ram_addr_t ram_size, } if (kernel_cmdline

[Qemu-devel] [PATCHv2 03/22] block: avoid buffer overrun by using pstrcpy, not strncpy

2012-05-30 Thread Jim Meyering
From: Jim Meyering Also, use PATH_MAX, rather than the arbitrary 1024. Using PATH_MAX is more consistent with other filename-related variables in this file, like backing_filename and tmp_filename. Acked-by: Kevin Wolf Signed-off-by: Jim Meyering --- block.c | 5 +++-- 1 file changed, 3

Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup

2012-05-30 Thread Jim Meyering
Anthony Liguori wrote: > On 05/09/2012 10:12 PM, Jim Meyering wrote: >> Peter Maydell wrote: >>> On 9 May 2012 15:01, Jim Meyering wrote: >>>> From 402100deb7e27b1d7ac619ebac963f861fae91b0 Mon Sep 17 00:00:00 2001 >>>> From: Jim Meyering >>>

[Qemu-devel] [PATCH] block: prevent snapshot mode $TMPDIR symlink attack

2012-05-28 Thread Jim Meyering
-2652. http://bugzilla.redhat.com/CVE-2012-2652 Signed-off-by: Jim Meyering --- Note that I haven't tried to see if the _WIN32 -GetLastError() return value is properly diagnosed as it is propagated up the call stack. block.c | 37 - block/vvfat.c

Re: [Qemu-devel] [PATCH 6/6] softmmu-semi: fix lock_user* functions not to deref NULL upon OOM

2012-05-24 Thread Jim Meyering
Peter Maydell wrote: > On 16 May 2012 14:08, Jim Meyering wrote: >> From: Jim Meyering >> >> Use g_malloc/g_free in place of malloc/free. >> >> Signed-off-by: Jim Meyering >> --- >>  softmmu-semi.h | 6 +++--- >>  1 file changed, 3 insertions(+

[Qemu-devel] [PATCH v2 6/6] softmmu-semi: fix lock_user* functions not to deref NULL upon OOM

2012-05-24 Thread Jim Meyering
Return NULL upon malloc failure. Signed-off-by: Jim Meyering --- Improved based on suggestion from Peter Maydell: Handle malloc failure rather than relying on g_malloc, since we can't afford to let guest-provided "len" induce g_malloc's abort. softmmu-semi.h | 5

[Qemu-devel] [PATCHv3 2/2] envlist.c: handle strdup failure

2012-05-22 Thread Jim Meyering
From: Jim Meyering Without this, envlist_to_environ may silently fail to copy all strings into the destination buffer, and both callers would leak any env strings allocated after a failing strdup, because the freeing code stops at the first NULL pointer. Signed-off-by: Jim Meyering

Re: [Qemu-devel] [PATCHv2 1/2] envlist.c: convert all TABs to equivalent spaces

2012-05-22 Thread Jim Meyering
Peter Maydell wrote: > On 22 May 2012 10:50, Jim Meyering wrote: >> From: Jim Meyering > > If we're going to go to the effort of a complete reindent > patch we should actually reindent to the QEMU coding style > standard, which is four-space, not eight. Good point. V3 is on its way.

Re: [Qemu-devel] [PATCH 2/9] tcg: declare __jit_debug_descriptor to be static

2012-05-22 Thread Jim Meyering
Peter Maydell wrote: > On 21 May 2012 21:10, Jim Meyering wrote: >> Peter Maydell wrote: >>> On 21 May 2012 20:51, Jim Meyering wrote: >>>> From: Jim Meyering >>>> >>>> >>>> Signed-off-by: Jim Meyering >>>&g

[Qemu-devel] [PATCHv2 2/9] tcg: __jit_debug_descriptor must *not* be static

2012-05-22 Thread Jim Meyering
From: Jim Meyering Add comments so no one else will be tempted to reduce the scope of this global variable. Signed-off-by: Jim Meyering --- tcg/tcg.c | 10 +++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index ab589c7..2793fa6 100644 --- a/tcg

[Qemu-devel] [PATCHv3 1/2] envlist.c: convert each TAB(width-4) to equivalent spaces

2012-05-22 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- envlist.c | 256 +++--- 1 file changed, 128 insertions(+), 128 deletions(-) diff --git a/envlist.c b/envlist.c index f2303cd..e44889b 100644 --- a/envlist.c +++ b/envlist.c @@ -8,13

[Qemu-devel] [PATCHv3 0/2] envlist.c: handle strdup failure

2012-05-22 Thread Jim Meyering
From: Jim Meyering Same as v2, but now with TABs converted using expand --tabs=4. Jim Meyering (2): envlist.c: convert each TAB(width-4) to equivalent spaces envlist.c: handle strdup failure envlist.c | 272 -- 1 file changed

Re: [Qemu-devel] [PATCH 1/3] envlist.c: handle strdup failure

2012-05-22 Thread Jim Meyering
Kevin Wolf wrote: > Am 22.05.2012 11:05, schrieb Jim Meyering: >> Kevin Wolf wrote: >>> A patch replacing tabs by spaces isn't really the kind of patches that >>> we would want to avoid during freeze. It's easy enough to check with git >>> diff -

[Qemu-devel] [PATCHv2 1/2] envlist.c: convert all TABs to equivalent spaces

2012-05-22 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- envlist.c | 256 +++--- 1 file changed, 128 insertions(+), 128 deletions(-) diff --git a/envlist.c b/envlist.c index f2303cd..be0addb 100644 --- a/envlist.c +++ b/envlist.c @@ -8,13

[Qemu-devel] [PATCHv2 2/2] envlist.c: handle strdup failure

2012-05-22 Thread Jim Meyering
From: Jim Meyering Without this, envlist_to_environ may silently fail to copy all strings into the destination buffer, and both callers would leak any env strings allocated after a failing strdup, because the freeing code stops at the first NULL pointer. Signed-off-by: Jim Meyering

[Qemu-devel] [PATCHv2 0/2] envlist.c: handle strdup failure

2012-05-22 Thread Jim Meyering
From: Jim Meyering This is the same as v1, except that two lines of non-leading TABs in envlist.c (indenting comments after code) have also been converted to use equivalent spaces instead of TABs. Jim Meyering (2): envlist.c: convert all TABs to equivalent spaces envlist.c: handle strdup

Re: [Qemu-devel] [PATCH 1/3] envlist.c: handle strdup failure

2012-05-22 Thread Jim Meyering
Kevin Wolf wrote: > A patch replacing tabs by spaces isn't really the kind of patches that > we would want to avoid during freeze. It's easy enough to check with git > diff -w that it doesn't change anything semantically. That makes sense, so I've posted two patches: 1) two patches: one repla

[Qemu-devel] [PATCH 2/2] envlist.c: handle strdup failure

2012-05-22 Thread Jim Meyering
From: Jim Meyering Without this, envlist_to_environ may silently fail to copy all strings into the destination buffer, and both callers would leak any env strings allocated after a failing strdup, because the freeing code stops at the first NULL pointer. Signed-off-by: Jim Meyering

[Qemu-devel] [PATCH 1/2] envlist.c: convert many leading TABs to spaces via expand -i

2012-05-22 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- envlist.c | 256 +++--- 1 file changed, 128 insertions(+), 128 deletions(-) diff --git a/envlist.c b/envlist.c index f2303cd..1d98108 100644 --- a/envlist.c +++ b/envlist.c @@ -8,13

[Qemu-devel] [PATCH 0/2] envlist.c: handle strdup failure

2012-05-22 Thread Jim Meyering
From: Jim Meyering Per discussion, let's switch envlist.c to indent with spaces, and then make the fix: Jim Meyering (2): envlist.c: convert many leading TABs to spaces via expand -i envlist.c: handle strdup failure envlist.c

[Qemu-devel] [PATCH 9/9] convert many more globals to static

2012-05-21 Thread Jim Meyering
From: Jim Meyering Minor exceptions: * arm-dis: move now-detected-as-unused static variables into #if-0'd block of code where they *are* used. * microblaze: remove decls of now-detected-as-unused vars Signed-off-by: Jim Meyering --- arm-dis.c | 8 ++--- c

[Qemu-devel] [PATCH 7/9] mips-dis: declare four globals to be "static"

2012-05-21 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- mips-dis.c | 15 +++ 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/mips-dis.c b/mips-dis.c index e3a6e0b..f6109a1 100644 --- a/mips-dis.c +++ b/mips-dis.c @@ -888,10 +888,9 @@ enum Many instructions are short

Re: [Qemu-devel] [PATCH 2/9] tcg: declare __jit_debug_descriptor to be static

2012-05-21 Thread Jim Meyering
Peter Maydell wrote: > On 21 May 2012 20:51, Jim Meyering wrote: >> From: Jim Meyering >> >> >> Signed-off-by: Jim Meyering >> --- >>  tcg/tcg.c | 2 +- >>  1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/tcg/tcg.c b/tcg/

[Qemu-devel] [PATCH 5/9] ccid: make backend_enum_table "static const" and adjust users

2012-05-21 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- hw/ccid-card-emulated.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/ccid-card-emulated.c b/hw/ccid-card-emulated.c index f4a6da4..440f050 100644 --- a/hw/ccid-card-emulated.c +++ b/hw/ccid-card-emulated.c

[Qemu-devel] [PATCH 8/9] bonito: declare bonito_state to be static

2012-05-21 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- hw/bonito.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/bonito.c b/hw/bonito.c index 77786f8..6bd0242 100644 --- a/hw/bonito.c +++ b/hw/bonito.c @@ -218,7 +218,7 @@ typedef struct PCIBonitoState } PCIBonitoState

[Qemu-devel] [PATCH 4/9] linux-user: arg_table need not have global scope

2012-05-21 Thread Jim Meyering
From: Jim Meyering Declare arg_table to be "static const", and adjust the two users to also be const. Signed-off-by: Jim Meyering --- linux-user/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 191b750..cc5b

[Qemu-devel] [PATCH 6/9] sheepdog: declare bdrv_sheepdog to be static

2012-05-21 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- block/sheepdog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index e01d371..fdb3eca 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2014,7 +2014,7 @@ static

[Qemu-devel] [PATCH 3/9] alpha-dis: remove unused global; declare others to be static

2012-05-21 Thread Jim Meyering
From: Jim Meyering alpha_num_operands: Remove both declarations of this unused global. alpha_opcodes: Declare static to limit scope. Remove duplicate decl. alpha_num_opcodes: Likewise. alpha_operands: Likewise. Signed-off-by: Jim Meyering --- alpha-dis.c | 26 +- 1

[Qemu-devel] [PATCH 3/9] alpha-dis: remove unused global; declare others to be static

2012-05-21 Thread Jim Meyering
From: Jim Meyering alpha_num_operands: Remove both declarations of this unused global. alpha_opcodes: Declare static to limit scope. Remove duplicate decl. alpha_num_opcodes: Likewise. alpha_operands: Likewise. Signed-off-by: Jim Meyering --- alpha-dis.c | 26 +- 1

[Qemu-devel] [PATCH 2/9] tcg: declare __jit_debug_descriptor to be static

2012-05-21 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- tcg/tcg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index ab589c7..350fdad 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2293,7 +2293,7 @@ void __jit_debug_register_code(void) /* Must statically

[Qemu-devel] [PATCH 2/9] tcg: declare __jit_debug_descriptor to be static

2012-05-21 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- tcg/tcg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index ab589c7..350fdad 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2293,7 +2293,7 @@ void __jit_debug_register_code(void) /* Must statically

[Qemu-devel] [PATCH 1/9] ccid: declare DEFAULT_ATR table to be "static const"

2012-05-21 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- hw/ccid-card-passthru.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ccid-card-passthru.c b/hw/ccid-card-passthru.c index bd6c777..1caaa45 100644 --- a/hw/ccid-card-passthru.c +++ b/hw/ccid-card-passthru.c @@ -27,7

[Qemu-devel] [PATCH 1/9] ccid: declare DEFAULT_ATR table to be "static const"

2012-05-21 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- hw/ccid-card-passthru.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ccid-card-passthru.c b/hw/ccid-card-passthru.c index bd6c777..1caaa45 100644 --- a/hw/ccid-card-passthru.c +++ b/hw/ccid-card-passthru.c @@ -27,7

[Qemu-devel] [PATCH 0/9] convert many more globals to "static"

2012-05-21 Thread Jim Meyering
From: Jim Meyering Following up on discussion here, http://marc.info/?t=13375948768&r=1&w=2 here are patches to limit the scope of the remaining global variables. Most changes simply added a preceding "static". However, in some cases, I've made minor additional c

Re: [Qemu-devel] [PATCH 0/3] tighten scope of accidentally global variables

2012-05-21 Thread Jim Meyering
Blue Swirl wrote: > On Mon, May 21, 2012 at 6:10 PM, Jim Meyering wrote: >> Blue Swirl wrote: >>> On Mon, May 21, 2012 at 10:03 AM, Jim Meyering wrote: >>>> From: Jim Meyering >>>> >>>> I noticed this commit, >>>> >>

Re: [Qemu-devel] [PATCH 0/3] tighten scope of accidentally global variables

2012-05-21 Thread Jim Meyering
Blue Swirl wrote: > On Mon, May 21, 2012 at 10:03 AM, Jim Meyering wrote: >> From: Jim Meyering >> >> I noticed this commit, >> >>    virtio-pci: add missing 'static' >> >> which made this change: >> >>    > -const MemoryReg

Re: [Qemu-devel] [PATCH 1/6] qcow2: don't leak buffer for unexpected qcow_version in header

2012-05-21 Thread Jim Meyering
Kevin Wolf wrote: > Am 16.05.2012 15:07, schrieb Jim Meyering: >> From: Jim Meyering >> >> >> Signed-off-by: Jim Meyering >> --- >> block/qcow2.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/block/qcow2.c b/block/qcow2.

[Qemu-devel] [PATCHv2 1/6] qcow2: don't leak buffer for unexpected qcow_version in header

2012-05-21 Thread Jim Meyering
Signed-off-by: Jim Meyering --- Thanks to Kevin Wolf for the improvement. block/qcow2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 655799c..c2e49cd 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -919,7 +919,8 @@ int

Re: [Qemu-devel] [PATCH 1/3] envlist.c: handle strdup failure

2012-05-21 Thread Jim Meyering
Blue Swirl wrote: > On Tue, May 15, 2012 at 1:04 PM, wrote: >> From: Jim Meyering >> >> Without this, envlist_to_environ may silently fail to copy all >> strings into the destination buffer, and both callers would leak >> any env strings allocated after a faili

[Qemu-devel] [PATCH 3/3] qemu-config: qemu_option_rom_opts, qemu_boot_opts: declare static

2012-05-21 Thread Jim Meyering
From: Jim Meyering Signed-off-by: Jim Meyering --- qemu-config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index be84a03..c03e52b 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -528,7 +528,7 @@ QemuOptsList qemu_spice_opts

  1   2   >