Added reaction for incorrect reserved bits.

This commit is contained in:
Yuri Silver 2022-01-07 15:31:58 +03:00
parent d5a104f493
commit 11ac750e87

View File

@ -636,8 +636,6 @@ var
buf: TBytes; buf: TBytes;
aPos, toRead: QWord; aPos, toRead: QWord;
begin begin
{ TODO: read aCount bytes }
// toRead := aCount;
aPos := 0; aPos := 0;
SetLength(aBytes, aCount); SetLength(aBytes, aCount);
repeat repeat
@ -977,7 +975,7 @@ begin
Raise EWebSocket.Create('Could not read frame header'); Raise EWebSocket.Create('Could not read frame header');
B1:=buffer[0]; B1:=buffer[0];
FFinalFrame:=(B1 and FlagFinalFrame) = FlagFinalFrame; FFinalFrame:=(B1 and FlagFinalFrame) = FlagFinalFrame;
FRSV:=B1 and ($F0) and (not FlagFinalFrame); FRSV:=(B1 and %01110000) shr 4;
FFrameType.AsFlag:=(B1 and $F); FFrameType.AsFlag:=(B1 and $F);
FPayload.Read(Buffer,aTransport); FPayload.Read(Buffer,aTransport);
Result:=True; Result:=True;
@ -1260,6 +1258,15 @@ Function TWSConnection.HandleIncoming(aFrame : TWSFrame) : Boolean;
begin begin
Result:=True; Result:=True;
// check Reserved
if aFrame.Reserved<>0 then
begin
Close('', CLOSE_PROTOCOL_ERROR);
UpdateCloseState;
Result:=false;
Exit;
end;
// here we handle payload. // here we handle payload.
if aFrame.FrameType<>ftContinuation then if aFrame.FrameType<>ftContinuation then
FInitialOpcode:=aFrame.FrameType; FInitialOpcode:=aFrame.FrameType;
@ -1282,16 +1289,16 @@ begin
// If our side sent the initial close, this is the reply, and we must disconnect (Result=false). // If our side sent the initial close, this is the reply, and we must disconnect (Result=false).
Result:=FCloseState=csNone; Result:=FCloseState=csNone;
if Result then if Result then
begin begin
FMessageContent:=aFrame.Payload.Data; FMessageContent:=aFrame.Payload.Data;
if not (woCloseExplicit in Options) then if not (woCloseExplicit in Options) then
begin begin
Send(ftClose); // Will update state Close('', CLOSE_NORMAL_CLOSURE); // Will update state
Result:=False; // We can disconnect. Result:=False; // We can disconnect.
end end
else else
UpdateCloseState UpdateCloseState
end end
else else
UpdateCloseState; UpdateCloseState;
end; end;