diff options
author | Damien George <damien.p.george@gmail.com> | 2018-05-31 21:47:26 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-05-31 21:47:26 +1000 |
commit | 98b9f0fc9d0fe14c5f13faf2e9b902422919594c (patch) | |
tree | af9d864c23bd89fb94f8b0d0365009c9b95a7a0e | |
parent | c60589c02b998794837489a6c6e51c4723af097f (diff) |
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.
-rw-r--r-- | extmod/modussl_mbedtls.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/extmod/modussl_mbedtls.c b/extmod/modussl_mbedtls.c index bd4b0c725..636f45f4e 100644 --- a/extmod/modussl_mbedtls.c +++ b/extmod/modussl_mbedtls.c @@ -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); #endif o->base.type = &ussl_socket_type; + o->sock = sock; int ret; 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); if (args->key.u_obj != MP_OBJ_NULL) { |