X-Git-Url: http://git.linex4red.de/pub/lufa.git/blobdiff_plain/617763ae20a9fbd35ed86956450f1555286636af..8a785549cf41ec8ba7dac6480e81d0de2c243c98:/LUFA/Drivers/USB/Class/Host/RNDISClassHost.c diff --git a/LUFA/Drivers/USB/Class/Host/RNDISClassHost.c b/LUFA/Drivers/USB/Class/Host/RNDISClassHost.c index 2a26c58f5..3981d7acf 100644 --- a/LUFA/Drivers/USB/Class/Host/RNDISClassHost.c +++ b/LUFA/Drivers/USB/Class/Host/RNDISClassHost.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2015. + Copyright (C) Dean Camera, 2021. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ /* - Copyright 2015 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -394,6 +394,7 @@ bool RNDIS_Host_IsPacketReceived(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfac uint8_t RNDIS_Host_ReadPacket(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo, void* Buffer, + const uint16_t BufferSize, uint16_t* const PacketLength) { uint8_t ErrorCode; @@ -422,13 +423,20 @@ uint8_t RNDIS_Host_ReadPacket(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceIn return ErrorCode; } - *PacketLength = (uint16_t)le32_to_cpu(DeviceMessage.DataLength); - Pipe_Discard_Stream(le32_to_cpu(DeviceMessage.DataOffset) - (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)), NULL); + const size_t ExpectedLength = (uint16_t)le32_to_cpu(DeviceMessage.DataLength); + + if (ExpectedLength > BufferSize) + *PacketLength = BufferSize; + else + *PacketLength = ExpectedLength; + Pipe_Read_Stream_LE(Buffer, *PacketLength, NULL); + if (ExpectedLength > BufferSize) + Pipe_Discard_Stream(ExpectedLength - BufferSize, NULL); if (!(Pipe_BytesInPipe())) Pipe_ClearIN();