WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] Fix segfault in get_all_assigned_devices

To: <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] Fix segfault in get_all_assigned_devices
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Date: Wed, 13 Jul 2011 12:37:19 +0100
Cc: Paul Durrant <paul.durrant@xxxxxxxxxx>
Delivery-date: Wed, 13 Jul 2011 04:32:55 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)
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@xxxxxxxxxxxxx>

diff -r 00d2c5ca26fd tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c   Fri Jul 08 18:35:24 2011 +0100
+++ b/tools/libxl/libxl_pci.c   Wed Jul 13 11:27:24 2011 +0000
@@ -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(libx
             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(libx
                     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;
 }

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>