xl: print BDF parse errors
PATCH 1/1 xl: print BDF parse errors
When parsing BDFs for pci-attach/detach, check the return of scanf rather than operating on random devices.
Signed-off-by Jeremy Fitzhardinge <[email protected]>
tools/libxl/xl_cmdimpl.c +8 -2
@@ -1519,7 +1519,10 @@find_domain (dom);memset (&pcidev,0x00 ,sizeof (pcidev)); -sscanf (bdf,PCI_BDF , &domain, &bus, &dev, &func); +if (sscanf (bdf,PCI_BDF , &domain, &bus, &dev, &func) !=4 ) { +fprintf (stderr,"pci-detach: malformed BDF specification \"%s\"\n" , bdf); +exit (2 ); + }libxl_device_pci_init (&pcidev, domain, bus, dev, func,0 );libxl_device_pci_remove (&ctx, domid, &pcidev); }
@@ -1558,7 +1561,10 @@find_domain (dom);memset (&pcidev,0x00 ,sizeof (pcidev)); -sscanf (bdf,PCI_BDF , &domain, &bus, &dev, &func); +if (sscanf (bdf,PCI_BDF , &domain, &bus, &dev, &func) !=4 ) { +fprintf (stderr,"pci-attach: malformed BDF specification \"%s\"\n" , bdf); +exit (2 ); + }libxl_device_pci_init (&pcidev, domain, bus, dev, func,0 );libxl_device_pci_add (&ctx, domid, &pcidev); }