Move the range check introduced by commit 2650d5e into
virDomainUSBAddressFindPort. That way both virDomainUSBAddressRelease
and virDomainUSBAddressSetAddHub can benefit from it.
Reported-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/domain_addr.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index 555da59..acff32f 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -1785,7 +1785,7 @@ virDomainUSBAddressFindPort(virDomainUSBAddressSetPtr addrs,
const char *portStr)
{
virDomainUSBAddressHubPtr hub = NULL;
- ssize_t i, lastIdx;
+ ssize_t i, lastIdx, targetPort;
if (info->addr.usb.bus >= addrs->nbuses ||
!addrs->buses[info->addr.usb.bus]) {
@@ -1820,7 +1820,15 @@ virDomainUSBAddressFindPort(virDomainUSBAddressSetPtr addrs,
}
}
- *targetIdx = info->addr.usb.port[lastIdx] - 1;
+ targetPort = info->addr.usb.port[lastIdx] - 1;
+ if (targetPort >= virBitmapSize(hub->portmap)) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("requested USB port %s not present on USB bus %u"),
+ portStr, info->addr.usb.bus);
+ return NULL;
+ }
+
+ *targetIdx = targetPort;
return hub;
}
@@ -2072,13 +2080,6 @@ virDomainUSBAddressReserve(virDomainDeviceInfoPtr info,
portStr)))
goto cleanup;
- if (targetPort >= virBitmapSize(targetHub->portmap)) {
- virReportError(VIR_ERR_XML_ERROR,
- _("requested USB port %s not present on USB bus %u"),
- portStr, info->addr.usb.bus);
- goto cleanup;
- }
-
if (virBitmapIsBitSet(targetHub->portmap, targetPort)) {
virReportError(VIR_ERR_XML_ERROR,
_("Duplicate USB address bus %u port %s"),
--
2.10.2
Show replies by date
On 01/30/2017 10:21 AM, Ján Tomko wrote:
Move the range check introduced by commit 2650d5e into
virDomainUSBAddressFindPort. That way both virDomainUSBAddressRelease
and virDomainUSBAddressSetAddHub can benefit from it.
Reported-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/domain_addr.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
ACK
John