usb: usbip tool: Check the return of get_nports()

If we get nonpositive number of ports, there is no sense to
continue, then fail gracefully.

In addition, the commit 0775a9cbc6 ("usbip: vhci extension:
modifications to vhci driver") introduced configurable numbers of
controllers and ports, but we have a static port number maximum,
MAXNPORT. If exceeded, the idev array will be overflown. We fix
it by validating the nports to make sure the port number max is
not exceeded.

Reviewed-by: Krzysztof Opasiak <[email protected]>
Signed-off-by: Yuyang Du <[email protected]>
Acked-by: Shuah Khan <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
This commit is contained in:
Yuyang Du 2017-05-22 18:20:15 +08:00 • committed by Greg Kroah-Hartman
commit c3509715fc

View file

@ -220,9 +220,16 @@ int usbip_vhci_driver_open(void)
}
vhci_driver->nports = get_nports();
dbg("available ports: %d", vhci_driver->nports);
if (vhci_driver->nports <= 0) {
err("no available ports");
goto err;
} else if (vhci_driver->nports > MAXNPORT) {
err("port number exceeds %d", MAXNPORT);
goto err;
}
if (refresh_imported_device_list())
goto err;