From f3b85a4a68154b69759ba116a3676cc3122bce26 Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Mon, 9 Dec 2024 23:05:34 +0000 Subject: [PATCH] fix: check for events on invalid sockets --- src/dpp/sslclient.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/dpp/sslclient.cpp b/src/dpp/sslclient.cpp index f9bb713334..60f7748e7a 100644 --- a/src/dpp/sslclient.cpp +++ b/src/dpp/sslclient.cpp @@ -491,9 +491,7 @@ void ssl_client::on_write(socket fd, const struct socket_events& e) { } void ssl_client::on_error(socket fd, const struct socket_events&, int error_code) { - if (sfd != INVALID_SOCKET) { - this->close(); - } + this->close(); } void ssl_client::read_loop() @@ -502,8 +500,24 @@ void ssl_client::read_loop() dpp::socket_events events( sfd, WANT_READ | WANT_WRITE | WANT_ERROR, - [this](socket fd, const struct socket_events &e) { on_read(fd, e); }, - [this](socket fd, const struct socket_events &e) { on_write(fd, e); }, + [this](socket fd, const struct socket_events &e) { + if (this->sfd == INVALID_SOCKET) { + close_socket(fd); + owner->socketengine->delete_socket(fd); + on_error(fd, e, 0); + return; + } + on_read(fd, e); + }, + [this](socket fd, const struct socket_events &e) { + if (this->sfd == INVALID_SOCKET) { + close_socket(fd); + owner->socketengine->delete_socket(fd); + on_error(fd, e, 0); + return; + } + on_write(fd, e); + }, [this](socket fd, const struct socket_events &e, int error_code) { on_error(fd, e, error_code); } ); owner->socketengine->register_socket(events);