From db2bc7ebeed87e404304402027bf137cf9ff89e2 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sat, 23 May 2026 13:30:24 +0200 Subject: [PATCH] cleanup: tcp server comments cleanup and added asserts --- toxcore/TCP_common.c | 1 + toxcore/TCP_server.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/toxcore/TCP_common.c b/toxcore/TCP_common.c index b74717dff..df9d2755a 100644 --- a/toxcore/TCP_common.c +++ b/toxcore/TCP_common.c @@ -299,6 +299,7 @@ int read_packet_tcp_secure_connection( } if (len_packet != *next_packet_length) { + // TODO(Green-Sky): this is probably unrecoverable LOGGER_WARNING(logger, "invalid packet length: %d, expected %d", len_packet, *next_packet_length); return 0; } diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index da8107bb0..16d99d4ba 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -8,6 +8,7 @@ */ #include "TCP_server.h" +#include #include #if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32) #include @@ -282,8 +283,8 @@ static int rm_connection_index(TCP_Server *_Nonnull tcp_server, TCP_Secure_Conne /** @brief Kill an accepted TCP_Secure_Connection * - * return -1 on failure. - * return 0 on success. + * @retval -1 on failure. + * @retval 0 on success. */ static int kill_accepted(TCP_Server *tcp_server, int index) { @@ -431,7 +432,7 @@ static int handle_tcp_routing_req(TCP_Server *_Nonnull tcp_server, uint32_t con_ uint32_t index = -1; TCP_Secure_Connection *con = &tcp_server->accepted_connection_array[con_id]; - /* If person tries to cennect to himself we deny the request*/ + /* If peer tries to connect to itself we deny the request. */ if (pk_equal(con->public_key, public_key)) { if (send_routing_response(tcp_server->logger, con, 0, public_key) == -1) { return -1; @@ -663,6 +664,7 @@ static int handle_tcp_packet(TCP_Server *_Nonnull tcp_server, uint32_t con_id, c return -1; } + assert(con_id < tcp_server->size_accepted_connections); TCP_Secure_Connection *const con = &tcp_server->accepted_connection_array[con_id]; netprof_record_packet(con->con.net_profile, data[0], length, PACKET_DIRECTION_RECV); @@ -1117,6 +1119,7 @@ static int do_unconfirmed(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Non static bool tcp_process_secure_packet(TCP_Server *_Nonnull tcp_server, uint32_t i) { + assert(i < tcp_server->size_accepted_connections); TCP_Secure_Connection *const conn = &tcp_server->accepted_connection_array[i]; uint8_t packet[MAX_PACKET_SIZE];