From 83b4137d41a4f0dbf18ccd6bb2e86ef7cb59686d Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Wed, 23 Jan 2013 15:43:21 +0000 Subject: [PATCH] Ensure nodeinfo struct is initialized to zero 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 --- src/nodeinfo.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 58c95f8d5a..162232215d 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -389,11 +389,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__) || \ @@ -870,6 +865,8 @@ int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) { virArch hostarch = virArchFromHost(); + memset(nodeinfo, 0, sizeof(*nodeinfo)); + if (virStrcpyStatic(nodeinfo->model, virArchToString(hostarch)) == NULL) return -1; -- 2.39.5