]> xenbits.xensource.com Git - xen.git/commitdiff
libxl: check return value of libxl__xs_directory in name2bdf
authorAnthony PERARD <anthony.perard@citrix.com>
Tue, 12 Jul 2022 06:38:51 +0000 (08:38 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 12 Jul 2022 06:38:51 +0000 (08:38 +0200)
libxl__xs_directory() can potentially return NULL without setting `n`.
As `n` isn't initialised, we need to check libxl__xs_directory()
return value before checking `n`. Otherwise, `n` might be non-zero
with `bdfs` NULL which would lead to a segv.

Fixes: 57bff091f4 ("libxl: add 'name' field to 'libxl_device_pci' in the IDL...")
Reported-by: "G.R." <firemeteor@users.sourceforge.net>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Tested-by: "G.R." <firemeteor@users.sourceforge.net>
tools/libs/light/libxl_pci.c

index 96f88795b66f47bdbd6470d03c2b05eaccd6444e..f4c4f175454d5dc1ea49784e296dc6f2362c1bee 100644 (file)
@@ -859,7 +859,7 @@ static int name2bdf(libxl__gc *gc, libxl_device_pci *pci)
     int rc = ERROR_NOTFOUND;
 
     bdfs = libxl__xs_directory(gc, XBT_NULL, PCI_INFO_PATH, &n);
-    if (!n)
+    if (!bdfs || !n)
         goto out;
 
     for (i = 0; i < n; i++) {