Skip to content

Commit

Permalink
fix: potential endless loop under extremely high load
Browse files Browse the repository at this point in the history
If there are more connections waiting to be accepted than
MAX_INCOMING_CONNECTIONS existing accepted connections are overwritten.
  • Loading branch information
sudden6 committed Dec 4, 2022
1 parent 9fae455 commit 701f4e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5cf49ad258527f6a2734a9d1f863084f66189338f47ca9d0a49482b4217577fb /usr/local/bin/tox-bootstrapd
2f7cc0e1acb07697f55fce064328e8193e54bd20189370b0c56c3b2264bdfa24 /usr/local/bin/tox-bootstrapd
13 changes: 8 additions & 5 deletions toxcore/TCP_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,12 +1033,15 @@ TCP_Server *new_TCP_server(const Logger *logger, const Random *rng, const Networ
non_null()
static void do_TCP_accept_new(TCP_Server *tcp_server)
{
for (uint32_t i = 0; i < tcp_server->num_listening_socks; ++i) {
Socket sock;
for (uint32_t sock_idx = 0; sock_idx < tcp_server->num_listening_socks; ++sock_idx) {

for (uint32_t connection_idx = 0; connection_idx < MAX_INCOMING_CONNECTIONS; ++connection_idx) {
const Socket sock = net_accept(tcp_server->ns, tcp_server->socks_listening[sock_idx]);

do {
sock = net_accept(tcp_server->ns, tcp_server->socks_listening[i]);
} while (accept_connection(tcp_server, sock) != -1);
if (accept_connection(tcp_server, sock) == -1) {
break;
}
}
}
}
#endif
Expand Down

0 comments on commit 701f4e9

Please sign in to comment.