diff options
author | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2011-10-06 19:06:20 +0100 |
---|---|---|
committer | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2011-10-06 19:06:20 +0100 |
commit | c57e5e842d1e1210777a4e0b1a16b9b710e7dbe1 (patch) | |
tree | 86c5c6fb4ca9d787abf6bbc52e2ceeb61b50168b | |
parent | d646af6f05a8f7b89c3e5331111b3c7df024d9cf (diff) | |
download | xen-c57e5e842d1e1210777a4e0b1a16b9b710e7dbe1.tar.gz xen-c57e5e842d1e1210777a4e0b1a16b9b710e7dbe1.tar.bz2 xen-c57e5e842d1e1210777a4e0b1a16b9b710e7dbe1.zip |
libxl: Fix segfault in get_all_assigned_devices
pcidevs is an array of ndev elements (ndev is the number of pci devices
assigend to a specific domain), but we access pcidevs + *num
where *num is the global number of pci devices assigned so far to all
domains in the system.
Fix the issue removing pcidevs and just realloc'ing *list every time we
want to add a new pci device to the array.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
xen-unstable changeset: 23685:5239811f92e1
Backport-requested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
-rw-r--r-- | tools/libxl/libxl_pci.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 931c6b35cf..b1d05d9e39 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -434,7 +434,6 @@ retry_transaction2: static int get_all_assigned_devices(libxl__gc *gc, libxl_device_pci **list, int *num) { - libxl_device_pci *pcidevs = NULL; char **domlist; unsigned int nd = 0, i; @@ -451,8 +450,7 @@ static int get_all_assigned_devices(libxl__gc *gc, libxl_device_pci **list, int int ndev = atoi(num_devs), j; char *devpath, *bdf; - pcidevs = libxl__calloc(gc, sizeof(*pcidevs), ndev); - for(j = (pcidevs) ? 0 : ndev; j < ndev; j++) { + for(j = 0; j < ndev; j++) { devpath = libxl__sprintf(gc, "/local/domain/0/backend/pci/%s/0/dev-%u", domlist[i], j); bdf = libxl__xs_read(gc, XBT_NULL, devpath); @@ -461,18 +459,17 @@ static int get_all_assigned_devices(libxl__gc *gc, libxl_device_pci **list, int if ( sscanf(bdf, PCI_BDF, &dom, &bus, &dev, &func) != 4 ) continue; - pcidev_init(pcidevs + *num, dom, bus, dev, func, 0); + *list = realloc(*list, sizeof(libxl_device_pci) * ((*num) + 1)); + if (*list == NULL) + return ERROR_NOMEM; + pcidev_init(*list + *num, dom, bus, dev, func, 0); (*num)++; } } } } - if ( 0 == *num ) { - pcidevs = NULL; - }else{ - *list = pcidevs; - } + libxl__ptr_add(gc, *list); return 0; } |