Skip to content

Commit 93aafd7

Browse files
committed
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: #2719
1 parent 819aa2b commit 93aafd7

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

toxcore/friend_connection.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,10 @@ void set_friend_request_callback(Friend_Connections *fr_c, fr_request_cb *fr_req
875875
int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint32_t nospam_num, const uint8_t *data,
876876
uint16_t length)
877877
{
878+
// FIXME: This max packet size is too large to be handled by receiving clients
879+
// when sent via the onion. We currently limit the length at a higher level, but
880+
// this bounds check should be fixed to represent the max size of a packet that
881+
// the onion client can handle.
878882
if (1 + sizeof(nospam_num) + length > ONION_CLIENT_MAX_DATA_SIZE || length == 0) {
879883
return -1;
880884
}

toxcore/friend_requests.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
#include "attributes.h"
1515
#include "friend_connection.h"
1616

17-
#define MAX_FRIEND_REQUEST_DATA_SIZE (ONION_CLIENT_MAX_DATA_SIZE - (1 + sizeof(uint32_t)))
17+
// FIXME: This should be the maximum size that an onion client can handle.
18+
#define MAX_FRIEND_REQUEST_DATA_SIZE (ONION_CLIENT_MAX_DATA_SIZE - 100)
1819

1920
typedef struct Friend_Requests Friend_Requests;
2021

toxcore/onion_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ non_null()
183183
unsigned int onion_getfriend_dht_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key);
184184

185185
#define ONION_DATA_IN_RESPONSE_MIN_SIZE (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE)
186+
187+
// FIXME: This is not the correct value; data this large will be dropped by the onion client.
186188
#define ONION_CLIENT_MAX_DATA_SIZE (MAX_DATA_REQUEST_SIZE - ONION_DATA_IN_RESPONSE_MIN_SIZE)
187189

188190
/** @brief Send data of length length to friendnum.

toxcore/tox.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ uint32_t tox_max_status_message_length(void);
274274
*
275275
* @deprecated The macro will be removed in 0.3.0. Use the function instead.
276276
*/
277-
#define TOX_MAX_FRIEND_REQUEST_LENGTH 1016
277+
#define TOX_MAX_FRIEND_REQUEST_LENGTH 921
278278

279279
uint32_t tox_max_friend_request_length(void);
280280

0 commit comments

Comments
 (0)