diff options
author | Michael Brown <mcb30@ipxe.org> | 2022-09-15 15:04:01 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2022-09-15 15:20:58 +0100 |
commit | 56b30364c5db6367279ffe88929f286f15680b40 (patch) | |
tree | 0062a8909e99c573d3c421d7d73a8321bff289f0 /src/hci | |
parent | 8fc3c26eae8d45a5391a39ee698817449299bd76 (diff) | |
download | ipxe-56b30364c5db6367279ffe88929f286f15680b40.tar.gz |
[pci] Check for wraparound in callers of pci_find_next()
The semantics of the bus:dev.fn parameter passed to pci_find_next()
are "find the first existent PCI device at this address or higher",
with the caller expected to increment the address between finding
devices. This does not allow the parameter to distinguish between the
two cases "start from address zero" and "wrapped after incrementing
maximal possible address", which could therefore lead to an infinite
loop in the degenerate case that a device with address ffff:ff:1f.7
really exists.
Fix by checking for wraparound in the caller (which is already
responsible for performing the increment).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/hci')
-rw-r--r-- | src/hci/commands/pci_cmd.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/hci/commands/pci_cmd.c b/src/hci/commands/pci_cmd.c index 515798baf..5bae66fbe 100644 --- a/src/hci/commands/pci_cmd.c +++ b/src/hci/commands/pci_cmd.c @@ -22,6 +22,7 @@ */ #include <stdio.h> +#include <errno.h> #include <getopt.h> #include <ipxe/pci.h> #include <ipxe/command.h> @@ -79,6 +80,10 @@ static int pciscan_exec ( int argc, char **argv ) { } else { /* Setting is defined: start searching from next location */ busdevfn = ( prev + 1 ); + if ( ! busdevfn ) { + rc = -ENOENT; + goto err_end; + } } /* Find next existent PCI device */ @@ -101,6 +106,7 @@ static int pciscan_exec ( int argc, char **argv ) { } err_store: + err_end: err_find_next: err_parse_setting: err_parse_options: |