Skip to content

Commit 9e92377

Browse files
authored
Update HTTPConnection.cpp -possible crash fix fhessel#106
WIP: Prevent crash on WebSocket request to non-WebSocket node. fhessel#106
1 parent 685158d commit 9e92377

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/HTTPConnection.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,17 @@ void HTTPConnection::loop() {
520520

521521
// Finally, after the handshake is done, we create the WebsocketHandler and change the internal state.
522522
if(websocketRequested) {
523-
_wsHandler = ((WebsocketNode*)resolvedResource.getMatchingNode())->newHandler();
524-
_wsHandler->initialize(this); // make websocket with this connection
525-
_connectionState = STATE_WEBSOCKET;
523+
HTTPNode *node = resolvedResource.getMatchingNode();
524+
525+
// Check for websocket request on non-websocket node:
526+
if (node == nullptr || node->_nodeType != HTTPNodeType::WEBSOCKET) {
527+
HTTPS_LOGW("Websocket request on non-websocket node rejected");
528+
raiseError(404, "Not Found");
529+
} else {
530+
_wsHandler = ((WebsocketNode *) node)->newHandler();
531+
_wsHandler->initialize(this); // make websocket with this connection
532+
_connectionState = STATE_WEBSOCKET;
533+
}
526534
} else {
527535
// Handling the request is done
528536
HTTPS_LOGD("Handler function done, request complete");

0 commit comments

Comments
 (0)