|
void WebSocket::handleFrame(const Frame::Header& frameHeader) { |
|
|
|
switch (frameHeader.opcode) { |
|
case Frame::OPCODE_CONTINUATION: |
|
if(m_lastOpcode < 0) { |
|
throw std::runtime_error("[oatpp::web::protocol::websocket::WebSocket::handleFrame()]: Invalid communication state."); |
|
} |
|
readPayload(frameHeader, nullptr); |
|
break; |
|
|
|
case Frame::OPCODE_TEXT: |
|
if(checkForContinuation(frameHeader)) { |
|
readPayload(frameHeader, nullptr); |
|
} else { |
|
throw std::runtime_error("[oatpp::web::protocol::websocket::WebSocket::handleFrame()]: Invalid communication state. OPCODE_CONTINUATION expected"); |
|
} |
|
break; |
|
|
In the above code, the
m_lastOpcode member is not updated when processing a frame with
opcode=Frame::OPCODE_CONTINUATION and
fin=true , so when processing
Frame::OPCODE_TEXT for the next frame,
checkForContinuation() returns
false and throws an exception. This results in a service disconnection.
|
bool WebSocket::checkForContinuation(const Frame::Header& frameHeader) { |
|
if(m_lastOpcode == Frame::OPCODE_TEXT || m_lastOpcode == Frame::OPCODE_BINARY) { |
|
return false; |
|
} |
|
if(frameHeader.fin) { |
|
m_lastOpcode = -1; |
|
} else { |
|
m_lastOpcode = frameHeader.opcode; |
|
} |
|
return true; |
|
} |
The same problem exists with asynchronous implementations
oatpp-websocket/src/oatpp-websocket/WebSocket.cpp
Lines 202 to 219 in d95c8ee
In the above code, the
m_lastOpcodemember is not updated when processing a frame withopcode=Frame::OPCODE_CONTINUATIONandfin=true, so when processingFrame::OPCODE_TEXTfor the next frame,checkForContinuation()returnsfalseand throws an exception. This results in a service disconnection.oatpp-websocket/src/oatpp-websocket/WebSocket.cpp
Lines 58 to 68 in d95c8ee
The same problem exists with asynchronous implementations