From: Keir Fraser Date: Fri, 28 May 2010 07:12:15 +0000 (+0100) Subject: xl: print BDF parse errors X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~12070 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=76a5dc5492c0385fe6f6c446512a41a2c3ba66bf;p=xen.git 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 --- diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 4e547c7730..59194b61ea 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -1519,7 +1519,10 @@ void pcidetach(char *dom, char *bdf) 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 @@ void pciattach(char *dom, char *bdf, char *vs) 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); }