Skip to content

Commit

Permalink
Update HTTPConnection.cpp -possible crash fix fhessel#106
Browse files Browse the repository at this point in the history
WIP: Prevent crash on WebSocket request to non-WebSocket node. fhessel#106
  • Loading branch information
gb-123-git committed Jan 23, 2022
1 parent 685158d commit 9e92377
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/HTTPConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,17 @@ void HTTPConnection::loop() {

// Finally, after the handshake is done, we create the WebsocketHandler and change the internal state.
if(websocketRequested) {
_wsHandler = ((WebsocketNode*)resolvedResource.getMatchingNode())->newHandler();
_wsHandler->initialize(this); // make websocket with this connection
_connectionState = STATE_WEBSOCKET;
HTTPNode *node = resolvedResource.getMatchingNode();

// Check for websocket request on non-websocket node:
if (node == nullptr || node->_nodeType != HTTPNodeType::WEBSOCKET) {
HTTPS_LOGW("Websocket request on non-websocket node rejected");
raiseError(404, "Not Found");
} else {
_wsHandler = ((WebsocketNode *) node)->newHandler();
_wsHandler->initialize(this); // make websocket with this connection
_connectionState = STATE_WEBSOCKET;
}
} else {
// Handling the request is done
HTTPS_LOGD("Handler function done, request complete");
Expand Down

0 comments on commit 9e92377

Please sign in to comment.