From b8d5803ba9d345236a0262282856fef3356bd14c Mon Sep 17 00:00:00 2001 From: jfreegman Date: Fri, 1 Mar 2024 22:12:31 -0500 Subject: [PATCH] fix: friend requests with very long messages are no longer dropped This is a band-aid solution that prevents friend requests with long messages from being dropped. However it doesn't solve the underlying problem, described here: https://github.com/TokTok/c-toxcore/issues/2719 --- toxcore/friend_connection.c | 4 ++++ toxcore/friend_requests.h | 3 ++- toxcore/onion_client.h | 2 ++ toxcore/tox.h | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index 33bfa40d346..0ea6f1bb6ca 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c @@ -875,6 +875,10 @@ void set_friend_request_callback(Friend_Connections *fr_c, fr_request_cb *fr_req int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint32_t nospam_num, const uint8_t *data, uint16_t length) { + // FIXME: This max packet size is too large to be handled by receiving clients + // when sent via the onion. We currently limit the length at a higher level, but + // this bounds check should be fixed to represent the max size of a packet that + // the onion client can handle. if (1 + sizeof(nospam_num) + length > ONION_CLIENT_MAX_DATA_SIZE || length == 0) { return -1; } diff --git a/toxcore/friend_requests.h b/toxcore/friend_requests.h index a78a570dfae..7e200c2d435 100644 --- a/toxcore/friend_requests.h +++ b/toxcore/friend_requests.h @@ -14,7 +14,8 @@ #include "attributes.h" #include "friend_connection.h" -#define MAX_FRIEND_REQUEST_DATA_SIZE (ONION_CLIENT_MAX_DATA_SIZE - (1 + sizeof(uint32_t))) +// FIXME: This should be the maximum size that an onion client can handle. +#define MAX_FRIEND_REQUEST_DATA_SIZE (ONION_CLIENT_MAX_DATA_SIZE - 100) typedef struct Friend_Requests Friend_Requests; diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 61e4e6fd1c3..b6a4f1a6bda 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h @@ -183,6 +183,8 @@ non_null() unsigned int onion_getfriend_dht_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key); #define ONION_DATA_IN_RESPONSE_MIN_SIZE (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE) + +// FIXME: This is not the correct value; data this large will be dropped by the onion client. #define ONION_CLIENT_MAX_DATA_SIZE (MAX_DATA_REQUEST_SIZE - ONION_DATA_IN_RESPONSE_MIN_SIZE) /** @brief Send data of length length to friendnum. diff --git a/toxcore/tox.h b/toxcore/tox.h index a0f4d20690b..c810ea3b487 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -283,7 +283,7 @@ uint32_t tox_max_status_message_length(void); * * @deprecated The macro will be removed in 0.3.0. Use the function instead. */ -#define TOX_MAX_FRIEND_REQUEST_LENGTH 1016 +#define TOX_MAX_FRIEND_REQUEST_LENGTH 921 uint32_t tox_max_friend_request_length(void);