Fixed invalid endpoint indexes causing memory corruption in device Clear/Set Feature standard requests (thanks to Peter Popovec).

This commit is contained in:
Dean Camera 2016-03-28 13:41:25 +11:00
parent df16148a02
commit 0c9856f405
2 changed files with 16 additions and 2 deletions

View File

@ -22,6 +22,7 @@
* - Fixed void pointer arithmetic in the low level and class driver RNDIS demo protocol decoders * - Fixed void pointer arithmetic in the low level and class driver RNDIS demo protocol decoders
* - Fixed low level RNDIS demo incorrectly setting the RNDIS state when a null packet filter was requested * - Fixed low level RNDIS demo incorrectly setting the RNDIS state when a null packet filter was requested
* - Fixed missing entries in several project's Atmel Studio integration files, such as driver INF files * - Fixed missing entries in several project's Atmel Studio integration files, such as driver INF files
* - Fixed invalid endpoint indexes causing memory corruption in device Clear/Set Feature standard requests (thanks to Peter Popovec)
* *
* <b>Changed:</b> * <b>Changed:</b>
* - Added signed alternative libUSB driver for the AVRISP-MKII clone project, to support Atmel Studio 7 (thanks to Atmel) * - Added signed alternative libUSB driver for the AVRISP-MKII clone project, to support Atmel Studio 7 (thanks to Atmel)

View File

@ -292,6 +292,7 @@ static void USB_Device_GetStatus(void)
switch (USB_ControlRequest.bmRequestType) switch (USB_ControlRequest.bmRequestType)
{ {
case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE): case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE):
{
#if !defined(NO_DEVICE_SELF_POWER) #if !defined(NO_DEVICE_SELF_POWER)
if (USB_Device_CurrentlySelfPowered) if (USB_Device_CurrentlySelfPowered)
CurrentStatus |= FEATURE_SELFPOWERED_ENABLED; CurrentStatus |= FEATURE_SELFPOWERED_ENABLED;
@ -302,9 +303,16 @@ static void USB_Device_GetStatus(void)
CurrentStatus |= FEATURE_REMOTE_WAKEUP_ENABLED; CurrentStatus |= FEATURE_REMOTE_WAKEUP_ENABLED;
#endif #endif
break; break;
}
case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT): case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT):
{
#if !defined(CONTROL_ONLY_DEVICE) #if !defined(CONTROL_ONLY_DEVICE)
Endpoint_SelectEndpoint((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK); uint8_t EndpointIndex = ((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK);
if (EndpointIndex >= ENDPOINT_TOTAL_ENDPOINTS)
return;
Endpoint_SelectEndpoint(EndpointIndex);
CurrentStatus = Endpoint_IsStalled(); CurrentStatus = Endpoint_IsStalled();
@ -312,6 +320,7 @@ static void USB_Device_GetStatus(void)
#endif #endif
break; break;
}
default: default:
return; return;
} }
@ -330,20 +339,23 @@ static void USB_Device_ClearSetFeature(void)
{ {
#if !defined(NO_DEVICE_REMOTE_WAKEUP) #if !defined(NO_DEVICE_REMOTE_WAKEUP)
case REQREC_DEVICE: case REQREC_DEVICE:
{
if ((uint8_t)USB_ControlRequest.wValue == FEATURE_SEL_DeviceRemoteWakeup) if ((uint8_t)USB_ControlRequest.wValue == FEATURE_SEL_DeviceRemoteWakeup)
USB_Device_RemoteWakeupEnabled = (USB_ControlRequest.bRequest == REQ_SetFeature); USB_Device_RemoteWakeupEnabled = (USB_ControlRequest.bRequest == REQ_SetFeature);
else else
return; return;
break; break;
}
#endif #endif
#if !defined(CONTROL_ONLY_DEVICE) #if !defined(CONTROL_ONLY_DEVICE)
case REQREC_ENDPOINT: case REQREC_ENDPOINT:
{
if ((uint8_t)USB_ControlRequest.wValue == FEATURE_SEL_EndpointHalt) if ((uint8_t)USB_ControlRequest.wValue == FEATURE_SEL_EndpointHalt)
{ {
uint8_t EndpointIndex = ((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK); uint8_t EndpointIndex = ((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK);
if (EndpointIndex == ENDPOINT_CONTROLEP) if (EndpointIndex == ENDPOINT_CONTROLEP || EndpointIndex >= ENDPOINT_TOTAL_ENDPOINTS)
return; return;
Endpoint_SelectEndpoint(EndpointIndex); Endpoint_SelectEndpoint(EndpointIndex);
@ -364,6 +376,7 @@ static void USB_Device_ClearSetFeature(void)
} }
break; break;
}
#endif #endif
default: default:
return; return;