extmod/modussl_mbedtls: Populate sock member right away in wrap_socket.
Otherwise the "sock" member may have an undefined value if wrap_socket fails with an exception and exits early, and then if the finaliser runs it will try to close an invalid stream object. Fixes issue #3828.
This commit is contained in:
parent
c60589c02b
commit
98b9f0fc9d
@ -124,6 +124,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
|||||||
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
||||||
#endif
|
#endif
|
||||||
o->base.type = &ussl_socket_type;
|
o->base.type = &ussl_socket_type;
|
||||||
|
o->sock = sock;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
mbedtls_ssl_init(&o->ssl);
|
mbedtls_ssl_init(&o->ssl);
|
||||||
@ -171,7 +172,6 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
o->sock = sock;
|
|
||||||
mbedtls_ssl_set_bio(&o->ssl, &o->sock, _mbedtls_ssl_send, _mbedtls_ssl_recv, NULL);
|
mbedtls_ssl_set_bio(&o->ssl, &o->sock, _mbedtls_ssl_send, _mbedtls_ssl_recv, NULL);
|
||||||
|
|
||||||
if (args->key.u_obj != MP_OBJ_NULL) {
|
if (args->key.u_obj != MP_OBJ_NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user