[libvirt] [PATCH] linuxNodeInfoCPUPopulate: avoid used-uninitialized via a test

Eric Blake eblake at redhat.com
Tue May 18 14:28:13 UTC 2010


On 05/18/2010 04:14 AM, Jim Meyering wrote:
>> * tests/nodeinfotest.c (linuxTestCompareFiles): Don't use
>> nodeinfo->member uninitialized.  linuxNodeInfoCPUPopulate requires
>> that some of its nodeinfo members (including threads) be initialized
>> upon input.  The nodeinfotest.c program lacked the initialization,
>> while the only other use (nodeGetInfo) did perform it.
>> It's not trivial to move the initialization into the function,
>> since nodeGetInfo sets at least one member after clearing the
>> buffer but before calling linuxNodeInfoCPUPopulate.

Thanks for documenting the analysis.

> +++ b/tests/nodeinfotest.c
> @@ -40,6 +40,8 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile
>      cpuinfo = fopen(cpuinfofile, "r");
>      if (!cpuinfo)
>          return -1;
> +
> +    memset(&nodeinfo, 0, sizeof(nodeinfo));
>      if (linuxNodeInfoCPUPopulate(cpuinfo, &nodeinfo) < 0) {

ACK.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100518/5eaf1a98/attachment-0001.sig>


More information about the libvir-list mailing list