diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2014-08-06 17:00:10 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2014-08-06 17:00:10 +0000 |
commit | f7edef4ab8c915cc80b32d641dd9940b3c314693 (patch) | |
tree | cd7a6d04745f21c20cb9a8e71825b56affb3b61a /lib/libpciaccess | |
parent | b0f68dda5ac4408d2e3a713dd3b3b6712634e68b (diff) |
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@
Diffstat (limited to 'lib/libpciaccess')
-rw-r--r-- | lib/libpciaccess/src/openbsd_pci.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/libpciaccess/src/openbsd_pci.c b/lib/libpciaccess/src/openbsd_pci.c index 69285e2f5..26360e84f 100644 --- a/lib/libpciaccess/src/openbsd_pci.c +++ b/lib/libpciaccess/src/openbsd_pci.c @@ -598,6 +598,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); @@ -612,16 +618,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++) { |