diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2014-08-06 17:08:10 +0200 |
---|---|---|
committer | Matthieu Herrb <matthieu@herrb.eu> | 2018-11-25 19:19:56 +0100 |
commit | 4dfb55a354bda581f5f751f806adfde936b221b5 (patch) | |
tree | c6a9f2c59928ad8ed9640dc0505f005fa77073da /src/openbsd_pci.c | |
parent | 71bc95ce79462f0ab66c819d47a37a94e85c6258 (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 'src/openbsd_pci.c')
-rw-r--r-- | src/openbsd_pci.c | 16 |
1 files changed, 6 insertions, 10 deletions
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++) { |