1
0
mirror of https://github.com/arduino-libraries/ArduinoHttpClient.git synced 2026-10-23 10:09:02 +03:00

WebSocketClient: check extended length/mask bytes are available

Only 2 header bytes were guaranteed before reading the extended length and
mask, so a partial header made read() return -1 and corrupt iRxSize. Bail
out until all header bytes have arrived.
This commit is contained in:
pennam
2026-07-13 15:50:30 +02:00
parent 532b516b73
commit d0a7577757

View File

@@ -206,6 +206,26 @@ int WebSocketClient::parseMessage()
iRxMasked = (length & 0x80);
length &= 0x7f;
// work out how many extended length and mask bytes follow the
// initial opcode + length bytes
int extendedLength = 0;
if (length == 126)
{
extendedLength = 2;
}
else if (length == 127)
{
extendedLength = 8;
}
int maskLength = iRxMasked ? (int)sizeof(iRxMaskKey) : 0;
// make sure the remaining header bytes are available before reading
// them, otherwise the frame header is incomplete
if (HttpClient::available() < (extendedLength + maskLength))
{
return 0;
}
// read the RX size
iRxSize = length;
if (length == 126)