[libvirt] [PATCH 3/6] virsh: use correct sizeof when allocating cpumap

2012-11-29 Thread Ján Tomko
Found by coverity:
Error: SIZEOF_MISMATCH (CWE-569):
libvirt-0.10.2/tools/virsh-domain.c:4754: suspicious_sizeof: Passing
argument 8UL /* sizeof (cpumap) */ to function
_vshCalloc(vshControl *, size_t, size_t, char const *, int) and
then casting the return value to unsigned char * is suspicious.

Error: SIZEOF_MISMATCH (CWE-569):
libvirt-0.10.2/tools/virsh-domain.c:4942: suspicious_sizeof: Passing
argument 8UL /* sizeof (cpumap) */ to function
_vshCalloc(vshControl *, size_t, size_t, char const *, int) and
then casting the return value to unsigned char * is suspicious.
---
 tools/virsh-domain.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 6d5a0ec..12da00d 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4768,7 +4768,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
 
 /* Pin mode: pinning specified vcpu to specified physical cpus*/
 
-cpumap = vshCalloc(ctl, cpumaplen, sizeof(cpumap));
+cpumap = vshCalloc(ctl, cpumaplen, sizeof(*cpumap));
 /* Parse cpulist */
 cur = cpulist;
 if (*cur == 0) {
@@ -4954,7 +4954,7 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
 
 /* Pin mode: pinning emulator threads to specified physical cpus*/
 
-cpumap = vshCalloc(ctl, cpumaplen, sizeof(cpumap));
+cpumap = vshCalloc(ctl, cpumaplen, sizeof(*cpumap));
 /* Parse cpulist */
 cur = cpulist;
 if (*cur == 0) {
-- 
1.7.8.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 3/6] virsh: use correct sizeof when allocating cpumap

2012-11-29 Thread Eric Blake
- Original Message -
 Found by coverity:
 Error: SIZEOF_MISMATCH (CWE-569):
 libvirt-0.10.2/tools/virsh-domain.c:4754: suspicious_sizeof:
 Passing
 argument 8UL /* sizeof (cpumap) */ to function
 _vshCalloc(vshControl *, size_t, size_t, char const *, int) and
 then casting the return value to unsigned char * is suspicious.
 
 Error: SIZEOF_MISMATCH (CWE-569):
 libvirt-0.10.2/tools/virsh-domain.c:4942: suspicious_sizeof:
 Passing
 argument 8UL /* sizeof (cpumap) */ to function
 _vshCalloc(vshControl *, size_t, size_t, char const *, int) and
 then casting the return value to unsigned char * is suspicious.
 ---
  tools/virsh-domain.c |4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

ACK.

 -cpumap = vshCalloc(ctl, cpumaplen, sizeof(cpumap));
 +cpumap = vshCalloc(ctl, cpumaplen, sizeof(*cpumap));

Bugs like this show why we prefer VIR_ALLOC_N.  Maybe we should
fix vshCalloc to be a thin wrapper around VIR_ALLOC_N, but that's
a bigger task for another day.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list