[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] Ensure nodeinfo struct is initialized to zero



On Wed, Jan 23, 2013 at 03:45:01PM +0000, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange redhat com>
> 
> When linuxNodeInfoCPUPopulate() method triggered use of an
> uninitialize value, since it did not initialize the 'sockets'
> field in the virNodeInfoPtr struct:
> 
> ==30020== Conditional jump or move depends on uninitialised value(s)
> ==30020==    at 0x5125DBD: linuxNodeInfoCPUPopulate (nodeinfo.c:513)
> ==30020==    by 0x51261A0: nodeGetInfo (nodeinfo.c:884)
> ==30020==    by 0x149B9B10: qemuCapsInit (qemu_capabilities.c:846)
> ==30020==    by 0x14A11B25: qemuCreateCapabilities (qemu_driver.c:424)
> ==30020==    by 0x14A12426: qemuStartup (qemu_driver.c:874)
> ==30020==    by 0x512A7AF: virStateInitialize (libvirt.c:822)
> ==30020==    by 0x40DE04: daemonRunStateInit (libvirtd.c:877)
> ==30020==    by 0x50ADCE5: virThreadHelper (virthreadpthread.c:161)
> ==30020==    by 0x328CA07D14: start_thread (pthread_create.c:308)
> ==30020==    by 0x328C6F246C: clone (clone.S:114)
> (happened twice)
> 
>         if (socks > nodeinfo->sockets)    <--- here
>             nodeinfo->sockets = socks;
> 
> Rather than doing this for each field, just make the caller memset
> the entire struct to zero.
> 
> Signed-off-by: Daniel P. Berrange <berrange redhat com>
> ---
>  src/nodeinfo.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/src/nodeinfo.c b/src/nodeinfo.c
> index 477104f..5b91a12 100644
> --- a/src/nodeinfo.c
> +++ b/src/nodeinfo.c
> @@ -387,11 +387,6 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
>      char *sysfs_nodedir = NULL;
>      char *sysfs_cpudir = NULL;
>  
> -    nodeinfo->cpus = 0;
> -    nodeinfo->mhz = 0;
> -    nodeinfo->cores = 0;
> -    nodeinfo->nodes = 0;
> -
>      /* Start with parsing CPU clock speed from /proc/cpuinfo */
>      while (fgets(line, sizeof(line), cpuinfo) != NULL) {
>  # if defined(__x86_64__) || \
> @@ -868,6 +863,8 @@ int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo)
>  {
>      virArch hostarch = virArchFromHost();
>  
> +    memset(nodeinfo, 0, sizeof(nodeinfo));
> +

Of course i meant   sizeof(*nodeinfo)

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]