Skip to content

Commit 761ddb9

Browse files
author
Alrik Vidstrom
committed
Fix crash at USB thumb drive insertion
Code that would return for the control endpoint had been removed in the ST port, which led to a null pointer being used as the this pointer in a USBDeviceConnected object, which caused a write to a small offset from address 0, which caused a fault.
1 parent 891b0d9 commit 761ddb9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/USBHost/USBHost.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,20 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint
697697
default:
698698
return false;
699699
}
700-
700+
#else
701+
// The code that follows this check shouldn't be executed for a control endpoint
702+
if (CONTROL_ENDPOINT == (ep->getType()))
703+
{
704+
return true;
705+
}
701706
#endif
702707
ep->dev = dev;
703-
dev->addEndpoint(intf_nb, ep);
704-
708+
// This check might not be necessary when the control endpoint check is added above, but
709+
// is included just in case
710+
if (nullptr != dev)
711+
{
712+
dev->addEndpoint(intf_nb, ep);
713+
}
705714
return true;
706715
}
707716

0 commit comments

Comments
 (0)