Skip to contentSkip to conversation

xhci: fix segfault

PATCH In review Gerd Hoffmann 2 participants 2 messages Jul 31, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xhci: fix segfault

Guest trying to reset a endpoint of a disconnected device resulted in xhci trying to dereference uport while being NULL, thereby crashing qemu. Fix that by adding a check. Drop unused dev variable while touching that code bit.

---
 hw/usb/hcd-xhci.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
hw/usb/hcd-xhci.c +2 -3
index a4cb13a..a922cb4 100644
@@ -1443,7 +1443,6 @@ static TRBCCode xhci_reset_ep(XHCIState *xhci, unsigned int slotid,
 {
     XHCISlot *slot;
     XHCIEPContext *epctx;
-    USBDevice *dev;
 
     trace_usb_xhci_ep_reset(slotid, epid);
     assert(slotid >= 1 && slotid <= xhci->numslots);
@@ -1479,8 +1478,8 @@ static TRBCCode xhci_reset_ep(XHCIState *xhci, unsigned int slotid,
         ep |= 0x80;
     }
 
-    dev = xhci->slots[slotid-1].uport->dev;
-    if (!dev) {
+    if (!xhci->slots[slotid-1].uport ||
+        !xhci->slots[slotid-1].uport->dev) {
         return CC_USB_TRANSACTION_ERROR;
     }
 
Signature · 1 line
1.7.9.7
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Gerd Hoffmann

Guest trying to reset a endpoint of a disconnected device resulted in xhci trying to dereference uport while being NULL, thereby crashing qemu. Fix that by adding a check. Drop unused dev variable while touching that code bit.

---
 hw/usb/hcd-xhci.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
hw/usb/hcd-xhci.c +0 -1
index a4cb13a..a922cb4 100644
@@ -1443,7 +1443,6 @@ static TRBCCode xhci_reset_ep(XHCIState *xhci, unsigned int slotid,
 {
     XHCISlot *slot;
     XHCIEPContext *epctx;
-    USBDevice *dev;
 
     trace_usb_xhci_ep_reset(slotid, epid);
     assert(slotid >= 1 && slotid <= xhci->numslots);

hw/usb/hcd-xhci.c static TRBCCode xhci_reset_ep(XHCIState *xhci, unsigned int slotid, · line 1485

Quoted 10 lines
hw/usb/hcd-xhci.c +2 -2
@@ -1479,8 +1478,8 @@ static TRBCCode xhci_reset_ep(XHCIState *xhci, unsigned int slotid,
         ep |= 0x80;
     }
 
-    dev = xhci->slots[slotid-1].uport->dev;
-    if (!dev) {
+    if (!xhci->slots[slotid-1].uport ||
+        !xhci->slots[slotid-1].uport->dev) {
         return CC_USB_TRANSACTION_ERROR;
     }