Skip to content

Fix ssl.SSLSocket bind() error checking #8962

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 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions shared-bindings/ssl/SSLSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ STATIC mp_obj_t ssl_sslsocket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
mp_raise_ValueError(MP_ERROR_TEXT("port must be >= 0"));
}

bool ok = common_hal_ssl_sslsocket_bind(self, host, hostlen, (uint32_t)port);
if (!ok) {
mp_raise_ValueError(MP_ERROR_TEXT("Error: Failure to bind"));
size_t error = common_hal_ssl_sslsocket_bind(self, host, hostlen, (uint32_t)port);
if (error != 0) {
mp_raise_OSError(error);
}

return mp_const_none;
Expand Down
7 changes: 2 additions & 5 deletions shared-bindings/ssl/SSLSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
* THE SOFTWARE.
*/

#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_SSL_SSLSOCKET_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_SSL_SSLSOCKET_H
#pragma once

#if CIRCUITPY_SSL_MBEDTLS
#include "shared-module/ssl/SSLSocket.h"
Expand All @@ -36,7 +35,7 @@
extern const mp_obj_type_t ssl_sslsocket_type;

ssl_sslsocket_obj_t *common_hal_ssl_sslsocket_accept(ssl_sslsocket_obj_t *self, uint8_t *ip, uint32_t *port);
bool common_hal_ssl_sslsocket_bind(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port);
size_t common_hal_ssl_sslsocket_bind(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port);
void common_hal_ssl_sslsocket_close(ssl_sslsocket_obj_t *self);
void common_hal_ssl_sslsocket_connect(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port);
bool common_hal_ssl_sslsocket_get_closed(ssl_sslsocket_obj_t *self);
Expand All @@ -45,5 +44,3 @@ bool common_hal_ssl_sslsocket_listen(ssl_sslsocket_obj_t *self, int backlog);
mp_uint_t common_hal_ssl_sslsocket_recv_into(ssl_sslsocket_obj_t *self, uint8_t *buf, uint32_t len);
mp_uint_t common_hal_ssl_sslsocket_send(ssl_sslsocket_obj_t *self, const uint8_t *buf, uint32_t len);
void common_hal_ssl_sslsocket_settimeout(ssl_sslsocket_obj_t *self, uint32_t timeout_ms);

#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SSL_SSLSOCKET_H
2 changes: 1 addition & 1 deletion shared-module/ssl/SSLSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ mp_uint_t common_hal_ssl_sslsocket_send(ssl_sslsocket_obj_t *self, const uint8_t
mp_raise_OSError(ret);
}

bool common_hal_ssl_sslsocket_bind(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port) {
size_t common_hal_ssl_sslsocket_bind(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port) {
return common_hal_socketpool_socket_bind(self->sock, host, hostlen, port);
}

Expand Down