From 4dfb55a354bda581f5f751f806adfde936b221b5 Mon Sep 17 00:00:00 2001 From: Jonathan Gray Date: Wed, 6 Aug 2014 17:08:10 +0200 Subject: calloc the pci_sys struct before probing for PCI. As the functions check if the member pointers are NULL but not the pointer to the struct itself. Reworked version of a diff from ratchov@ who created it to prevent a xserver crash on zaurus where there is no PCI. 'looks ok' matthieu@, ok deraadt@ --- src/openbsd_pci.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/openbsd_pci.c') diff --git a/src/openbsd_pci.c b/src/openbsd_pci.c index 603bdaa..08f6f7b 100644 --- a/src/openbsd_pci.c +++ b/src/openbsd_pci.c @@ -627,6 +627,12 @@ pci_system_openbsd_create(void) if (ndomains > 0) return 0; + pci_sys = calloc(1, sizeof(struct pci_system)); + if (pci_sys == NULL) + return ENOMEM; + + pci_sys->methods = &openbsd_pci_methods; + for (domain = 0; domain < sizeof(pcifd) / sizeof(pcifd[0]); domain++) { snprintf(path, sizeof(path), "/dev/pci%d", domain); pcifd[domain] = open(path, O_RDWR | O_CLOEXEC); @@ -641,16 +647,6 @@ pci_system_openbsd_create(void) if (ndomains == 0) return ENXIO; - pci_sys = calloc(1, sizeof(struct pci_system)); - if (pci_sys == NULL) { - for (domain = 0; domain < ndomains; domain++) - close(pcifd[domain]); - ndomains = 0; - return ENOMEM; - } - - pci_sys->methods = &openbsd_pci_methods; - ndevs = 0; for (domain = 0; domain < ndomains; domain++) { for (bus = 0; bus < 256; bus++) { -- cgit v1.2.3