Skip to content

Commit

Permalink
Handle incomplete frame to prevent WebsocketClient ending in an endle…
Browse files Browse the repository at this point in the history
…ss loop (#1189)
  • Loading branch information
jochenjagers authored and slaff committed Jul 21, 2017
1 parent 08143b5 commit f4c2d01
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sming/SmingCore/Network/WebsocketFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ uint8_t WebsocketFrameClass::_getFrameSizes(uint8_t* buffer, size_t length)
{
_nextReadOffset = 0; // single websocket frame in buffer
}
else if(length < _nextReadOffset)
{
// Frame is incomplete
_frameType = WSFrameType::incomplete;
return false;
}

return true;
}
Expand All @@ -197,7 +203,8 @@ uint8_t WebsocketFrameClass::decodeFrame(uint8_t * buffer, size_t length)
WSFrameType op = (WSFrameType)(buffer[0] & 0b00001111); // Extracting Opcode
uint8_t fin = buffer[0] & 0b10000000; // Extracting Fin Bit (Single Frame)

if (op == WSFrameType::continuation || op == WSFrameType::text || op == WSFrameType::binary) //Data frames
// At least there must be one byte that op and fin are vaild
if (length > 0 && op == WSFrameType::continuation || op == WSFrameType::text || op == WSFrameType::binary) //Data frames
{
if (fin > 0)
{
Expand Down

0 comments on commit f4c2d01

Please sign in to comment.