Skip to content

Commit ad2375f

Browse files
committed
fix: potential endless loop under extremely high load
If there are more connections waiting to be accepted than MAX_INCOMING_CONNECTIONS existing accepted connections are overwritten.
1 parent 9fae455 commit ad2375f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5cf49ad258527f6a2734a9d1f863084f66189338f47ca9d0a49482b4217577fb /usr/local/bin/tox-bootstrapd
1+
2f7cc0e1acb07697f55fce064328e8193e54bd20189370b0c56c3b2264bdfa24 /usr/local/bin/tox-bootstrapd

toxcore/TCP_server.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,12 +1033,15 @@ TCP_Server *new_TCP_server(const Logger *logger, const Random *rng, const Networ
10331033
non_null()
10341034
static void do_TCP_accept_new(TCP_Server *tcp_server)
10351035
{
1036-
for (uint32_t i = 0; i < tcp_server->num_listening_socks; ++i) {
1037-
Socket sock;
1036+
for (uint32_t sock_idx = 0; sock_idx < tcp_server->num_listening_socks; ++sock_idx) {
1037+
1038+
for (uint32_t connection_idx = 0; connection_idx < MAX_INCOMING_CONNECTIONS; ++connection_idx) {
1039+
const Socket sock = net_accept(tcp_server->ns, tcp_server->socks_listening[sock_idx]);
10381040

1039-
do {
1040-
sock = net_accept(tcp_server->ns, tcp_server->socks_listening[i]);
1041-
} while (accept_connection(tcp_server, sock) != -1);
1041+
if (accept_connection(tcp_server, sock) == -1) {
1042+
break;
1043+
}
1044+
}
10421045
}
10431046
}
10441047
#endif

0 commit comments

Comments
 (0)