diff options
author | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2011-07-14 15:49:49 +0100 |
---|---|---|
committer | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2011-07-14 15:49:49 +0100 |
commit | f4766463d45203382484ae77fbbf1f2aa12d5dcb (patch) | |
tree | ae20c22c926385b31b435653aaf2c69b5edf7176 /tools/libxl/libxl_pci.c | |
parent | 3d250640601709b9a6530453bffdeaeeca57741c (diff) | |
download | xen-f4766463d45203382484ae77fbbf1f2aa12d5dcb.tar.gz xen-f4766463d45203382484ae77fbbf1f2aa12d5dcb.tar.bz2 xen-f4766463d45203382484ae77fbbf1f2aa12d5dcb.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>
Diffstat (limited to 'tools/libxl/libxl_pci.c')
-rw-r--r-- | tools/libxl/libxl_pci.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 8d2c4d19a3..89f5a30224 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -422,7 +422,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; @@ -439,8 +438,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); @@ -449,19 +447,16 @@ 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 ) { - free(pcidevs); - pcidevs = NULL; - }else{ - *list = pcidevs; - } + libxl__ptr_add(gc, *list); return 0; } |