8000 extmod/modssl_mbedtls: Fix ioctl of a socket in closed/error state. · micropython/micropython@d529c20 · GitHub
[go: up one dir, main page]

Skip to content

Commit d529c20

Browse files
committed
extmod/modssl_mbedtls: Fix ioctl of a socket in closed/error state.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 20d3a6b commit d529c20

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

extmod/modssl_mbedtls.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,20 @@ STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i
486486
mp_uint_t ret = 0;
487487
uintptr_t saved_arg = 0;
488488
mp_obj_t sock = self->sock;
489-
if (sock == MP_OBJ_NULL || (request != MP_STREAM_CLOSE && self->last_error != 0)) {
490-
// Closed or error socket:
491-
return MP_STREAM_POLL_NVAL;
492-
}
493489

494490
if (request == MP_STREAM_CLOSE) {
491+
if (sock == MP_OBJ_NULL) {
492+
// Already closed socket, do nothing.
493+
return 0;
494+
}
495495
self->sock = MP_OBJ_NULL;
496496
mbedtls_ssl_free(&self->ssl);
497497
} else if (request == MP_STREAM_POLL) {
498+
if (sock == MP_OBJ_NULL || self->last_error != 0) {
499+
// Closed or error socket, return NVAL flag.
500+
return MP_STREAM_POLL_NVAL;
501+
}
502+
498503
// If the library signaled us that it needs reading or writing, only check that direction,
499504
// but save what the caller asked because we need to restore it later
500505
if (self->poll_mask && (arg & MP_STREAM_POLL_RDWR)) {

tests/extmod/ssl_ioctl.py.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
10 OSError
44
4 0
55
3 32
6-
4 32
6+
4 0

0 commit comments

Comments
 (0)
0