Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on double free #935

Open
moritz89 opened this issue Feb 19, 2025 · 3 comments
Open

Crash on double free #935

moritz89 opened this issue Feb 19, 2025 · 3 comments

Comments

@moritz89
Copy link
Contributor

There is a crash on double free if an SSL/TLS connection is used and it disconnects and then tries to connect again.

# src/WebSocketsClient.cpp

void WebSocketsClient::loop(void) {
     if(!clientIsConnected(&_client)) {
        if(_client.isSSL) {
            if(_client.ssl) {
# ...
                delete _client.ssl; # L250
# ...
            }
            _client.ssl = new WEBSOCKETS_NETWORK_SSL_CLASS();
            _client.tcp = _client.ssl;
        }
    }
}

void WebSocketsClient::clientDisconnect(WSclient_t * client) {
    if(client->tcp) {
# ...
        client->tcp = NULL; # L558
    }

    client->cCode        = 0;
    client->cKey         = "";
}

The fix is to set client->ssl = NULL; after line 558. The cause is the ssl pointer has not been set to null after the same object was deleted from the tcp pointer.

@Links2004
Copy link
Owner

which version of the libary and mcp are you using?

SSL is reset in the here:

if(client->isSSL && client->ssl) {
if(client->ssl->connected()) {
client->ssl->flush();
client->ssl->stop();
}
event = true;
delete client->ssl;
client->ssl = NULL;
client->tcp = NULL;
}

@moritz89
Copy link
Contributor Author

Ahhh, I see the cause now. I am testing a new WEBSOCKETS_NETWORK_TYPE and skipped the define check on L528. Can probably close this and handle it in an MR that would address that.

arduinoWebSockets == 2.6.1

@Links2004
Copy link
Owner

it may make sense to use this for L528
#if defined(HAS_SSL)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants