Skip to content

Fixed failure paths not setting socket to -1 consistently, changed close to lwip_close to resolve assert #6942

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

Merged
merged 2 commits into from
Jul 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions libraries/WiFiClientSecure/src/ssl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,21 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
int res = lwip_connect(ssl_client->socket, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
if (res < 0 && errno != EINPROGRESS) {
log_e("connect on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno));
close(ssl_client->socket);
lwip_close(ssl_client->socket);
ssl_client->socket = -1;
return -1;
}

res = select(ssl_client->socket + 1, nullptr, &fdset, nullptr, timeout<0 ? nullptr : &tv);
if (res < 0) {
log_e("select on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno));
close(ssl_client->socket);
lwip_close(ssl_client->socket);
ssl_client->socket = -1;
return -1;
} else if (res == 0) {
log_i("select returned due to timeout %d ms for fd %d", timeout, ssl_client->socket);
close(ssl_client->socket);
lwip_close(ssl_client->socket);
ssl_client->socket = -1;
return -1;
} else {
int sockerr;
Expand All @@ -120,13 +123,15 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p

if (res < 0) {
log_e("getsockopt on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno));
close(ssl_client->socket);
lwip_close(ssl_client->socket);
ssl_client->socket = -1;
return -1;
}

if (sockerr != 0) {
log_e("socket error on fd %d, errno: %d, \"%s\"", ssl_client->socket, sockerr, strerror(sockerr));
close(ssl_client->socket);
lwip_close(ssl_client->socket);
ssl_client->socket = -1;
return -1;
}
}
Expand Down Expand Up @@ -319,7 +324,7 @@ void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, cons
log_v("Cleaning SSL connection.");

if (ssl_client->socket >= 0) {
close(ssl_client->socket);
lwip_close(ssl_client->socket);
ssl_client->socket = -1;
}

Expand Down