mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-12 22:14:25 +00:00
sockets.c: Make sock_inc_used overflow check robust.
Before this patch, it was possible that the overflow check might miss an overflow event. e.g. Consider 2 threads, both executing this method. u8_t fd_used is on 255... Thread A -> atomically increment fd_used (which is now 0) Thread B -> atomically increment fd_used (which is now 1) Thread A -> check overflow... sees everything ok Thread B -> check overflow... sees everything ok And the overflow is missed :( Signed-off-by: goldsimon <goldsimon@gmx.de>
This commit is contained in:
parent
7ac3056da9
commit
8e83e206f4
@ -374,9 +374,14 @@ lwip_socket_thread_cleanup(void)
|
||||
static void
|
||||
sock_inc_used(struct lwip_sock *sock)
|
||||
{
|
||||
SYS_ARCH_DECL_PROTECT(lev);
|
||||
|
||||
LWIP_ASSERT("sock != NULL", sock != NULL);
|
||||
SYS_ARCH_INC(sock->fd_used, 1);
|
||||
|
||||
SYS_ARCH_PROTECT(lev);
|
||||
++sock->fd_used;
|
||||
LWIP_ASSERT("sock->fd_used != 0", sock->fd_used != 0);
|
||||
SYS_ARCH_UNPROTECT(lev);
|
||||
}
|
||||
|
||||
/* In full-duplex mode,sock->fd_used != 0 prevents a socket descriptor from being
|
||||
|
Loading…
x
Reference in New Issue
Block a user