Skip to content

Commit 624630d

Browse files
committed
fix: prevent possible null pointer issues
1 parent 13a7896 commit 624630d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/machine/usb.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ func handleStandardSetup(setup usb.Setup) bool {
213213
if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP
214214
isRemoteWakeUpEnabled = false
215215
} else if setup.WValueL == 0 { // ENDPOINTHALT
216-
if usbStallHandler[setup.WIndex&0x7F] != nil {
216+
if setup.WIndex < usb.NumberOfEndpoints && usbStallHandler[setup.WIndex&0x7F] != nil {
217+
// Host has requested to clear an endpoint stall. If the request is addressed to
218+
// an endpoint with a configured StallHandler, forward the message on.
219+
// The 0x7F mask is used to clear the direction bit from the endpoint number
217220
return usbStallHandler[setup.WIndex&0x7F](setup)
218221
}
219222
isEndpointHalt = false
@@ -225,7 +228,10 @@ func handleStandardSetup(setup usb.Setup) bool {
225228
if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP
226229
isRemoteWakeUpEnabled = true
227230
} else if setup.WValueL == 0 { // ENDPOINTHALT
228-
if usbStallHandler[setup.WIndex&0x7F] != nil {
231+
if setup.WIndex < usb.NumberOfEndpoints && usbStallHandler[setup.WIndex&0x7F] != nil {
232+
// Host has requested to stall an endpoint. If the request is addressed to
233+
// an endpoint with a configured StallHandler, forward the message on.
234+
// The 0x7F mask is used to clear the direction bit from the endpoint number
229235
return usbStallHandler[setup.WIndex&0x7F](setup)
230236
}
231237
isEndpointHalt = true

0 commit comments

Comments
 (0)