mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 01:40:14 +01:00
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>
This commit is contained in:
committed by
Damien George
parent
2a46759fe8
commit
2f04381aeb
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user