diff options
author | Damien George <damien@micropython.org> | 2020-08-30 13:20:51 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-08-30 13:20:51 +1000 |
commit | d1995e50ebda074f8151609bb4c95d4c31072513 (patch) | |
tree | 31ccbfbb14315087bd23563ef095992db75f645d /extmod/modlwip.c | |
parent | 06659077a81b85882254cf0953c33b27614e018e (diff) |
extmod/modlwip: Fix error return for TCP recv when not connected.
This commit fixes the cases when a TCP socket is in STATE_NEW,
STATE_LISTENING or STATE_CONNECTING and recv() is called on it. It now
raises ENOTCONN instead of a random error code due to it previously
indexing beyond the start of error_lookup_table[].
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/modlwip.c')
-rw-r--r-- | extmod/modlwip.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 216e81749..1d557a6a8 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -757,8 +757,11 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_ return 0; } } else if (socket->state != STATE_CONNECTED) { - assert(socket->state < 0); - *_errno = error_lookup_table[-socket->state]; + if (socket->state >= STATE_NEW) { + *_errno = MP_ENOTCONN; + } else { + *_errno = error_lookup_table[-socket->state]; + } return -1; } } |