]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Fix crash in virNetDevGetVirtualFunctions
authorLaine Stump <laine@laine.org>
Tue, 9 Apr 2013 18:06:51 +0000 (14:06 -0400)
committerLaine Stump <laine@laine.org>
Tue, 9 Apr 2013 18:26:12 +0000 (14:26 -0400)
Commit 9a3ff01d7f16cc280ce3176620c0714f55511a65 (which was ACKed at
the end of January, but for some reason didn't get pushed until during
the 1.0.4 freeze) fixed the logic in virPCIGetVirtualFunctions().
Unfortunately, a typo in the fix (replacing VIR_REALLOC_N with
VIR_ALLOC_N during code movement) caused not only a memory leak, but
also resulted in most of the elements of the result array being
replaced with NULL. virNetDevGetVirtualFunctions() assumed (and I think
rightly so) that virPCIGetVirtualFunctions() wouldn't return any NULL
elements in the array, so it ended up segfaulting.

This was found when attempting to use a virtual network with an
auto-created pool of SRIOV VFs, e.g.:

    <forward mode='hostdev' managed='yes'>
      <pf dev='eth4'/>
    </forward>

(the pool of PCI addresses is discovered by calling
virNetDevGetVirtualFunctions() on the PF dev).

src/util/virpci.c

index a0da1cd005e80d8f2fa3ee0b74e24df0bf943da2..85cd6948d721ea2f48cad5d50b26d7b43f5c8b48 100644 (file)
@@ -2026,8 +2026,8 @@ virPCIGetVirtualFunctions(const char *sysfs_path,
                 continue;
             }
 
-            if (VIR_ALLOC_N(*virtual_functions,
-                            *num_virtual_functions + 1) < 0) {
+            if (VIR_REALLOC_N(*virtual_functions,
+                              *num_virtual_functions + 1) < 0) {
                 virReportOOMError();
                 VIR_FREE(config_addr);
                 goto error;