diff options
| author | Andrew Leech <andrew.leech@planetinnovation.com.au> | 2025-05-21 11:16:54 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-06-26 12:46:45 +1000 |
| commit | 2f04381aeb18b11a9973b8bf461bdb5cfd46edc5 (patch) | |
| tree | 1607be512a1abc6da9aa5a8718cc635d67fc94ed /extmod/modlwip.c | |
| parent | 2a46759fe83a5295f7c06e2dab37c3f85848800e (diff) | |
extmod/modlwip: Fix crash when calling recv on listening socket.
Add check to prevent calling recv on a socket in the listening state. This
prevents a crash/hard fault when user code mistakenly tries to recv on the
listening socket instead of on the accepted connection.
Add corresponding test case to demonstrate the bug.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Diffstat (limited to 'extmod/modlwip.c')
| -rw-r--r-- | extmod/modlwip.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 65a3412ec..b53559ed8 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -825,6 +825,12 @@ static mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_ // Check for any pending errors STREAM_ERROR_CHECK(socket); + if (socket->state == STATE_LISTENING) { + // original socket in listening state, not the accepted connection. + *_errno = MP_ENOTCONN; + return -1; + } + if (socket->incoming.tcp.pbuf == NULL) { // Non-blocking socket or flag |
