tools: Fix wild memory allocations from c/s 250f0b4 and 85d78b4
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 18 May 2015 12:57:24 +0000 (13:57 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 21 May 2015 14:19:50 +0000 (15:19 +0100)
These changesets cause the respective libxc functions to unconditonally
dereference their max_cpus/nodes parameters as part of initial memory
allocations.  It will fail at obtaining the correct number of cpus/nodes from
Xen, as the guest handles will not be NULL.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/libxl/libxl.c
tools/misc/xenpm.c
tools/python/xen/lowlevel/xc/xc.c

index 9cc45b4770bf3efa0ac7450353dba1841564dc1e..9117b018385edd1de5d6f1770bc57f29e7733747 100644 (file)
@@ -5106,7 +5106,7 @@ libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out)
     xc_cputopo_t *cputopo;
     libxl_cputopology *ret = NULL;
     int i;
-    unsigned num_cpus;
+    unsigned num_cpus = 0;
 
     /* Setting buffer to NULL makes the call return number of CPUs */
     if (xc_cputopoinfo(ctx->xch, &num_cpus, NULL))
@@ -5192,7 +5192,7 @@ libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr)
     uint32_t *distance;
     libxl_numainfo *ret = NULL;
     int i, j;
-    unsigned num_nodes;
+    unsigned num_nodes = 0;
 
     if (xc_numainfo(ctx->xch, &num_nodes, NULL, NULL)) {
         LOGE(ERROR, "Unable to determine number of nodes");
index fe2c001841c9c9c38f7135ef041f99adefabfe96..2f9bd8efa9bb2bbe4c766d7ee58bc641d8a3134e 100644 (file)
@@ -356,7 +356,7 @@ static void signal_int_handler(int signo)
     struct timeval tv;
     int cx_cap = 0, px_cap = 0;
     xc_cputopo_t *cputopo = NULL;
-    unsigned max_cpus;
+    unsigned max_cpus = 0;
 
     if ( xc_cputopoinfo(xc_handle, &max_cpus, NULL) != 0 )
     {
@@ -961,7 +961,7 @@ void scaling_governor_func(int argc, char *argv[])
 void cpu_topology_func(int argc, char *argv[])
 {
     xc_cputopo_t *cputopo = NULL;
-    unsigned max_cpus;
+    unsigned max_cpus = 0;
     int i, rc;
 
     if ( xc_cputopoinfo(xc_handle, &max_cpus, NULL) != 0 )
index fbd93db114a500c9d8e3d6773ec0b540d4e63fe0..c77e15b833bfd617b35fbdbc115da00ec49e9b75 100644 (file)
@@ -1221,7 +1221,7 @@ static PyObject *pyxc_getcpuinfo(XcObject *self, PyObject *args, PyObject *kwds)
 static PyObject *pyxc_topologyinfo(XcObject *self)
 {
     xc_cputopo_t *cputopo = NULL;
-    unsigned i, num_cpus;
+    unsigned i, num_cpus = 0;
     PyObject *ret_obj = NULL;
     PyObject *cpu_to_core_obj, *cpu_to_socket_obj, *cpu_to_node_obj;
 
@@ -1293,7 +1293,7 @@ out:
 
 static PyObject *pyxc_numainfo(XcObject *self)
 {
-    unsigned i, j, num_nodes;
+    unsigned i, j, num_nodes = 0;
     uint64_t free_heap;
     PyObject *ret_obj = NULL, *node_to_node_dist_list_obj;
     PyObject *node_to_memsize_obj, *node_to_memfree_obj;