From b77e407b6fe4800eb9c7abce405f804429884643 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sat, 11 Aug 2018 13:07:37 +0000 Subject: [PATCH] Avoid passing -1 as friend connection to new groups. Somehow it still works because the lower levels can deal with inconsistent/broken state, but this lets us avoid that broken state in the first place. If a friend connection doesn't exist, we don't add it to our group. --- toxcore/group.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/toxcore/group.c b/toxcore/group.c index 1ef3d374..20075c8b 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -1492,7 +1492,13 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con memcpy(&other_groupnum, data + 1, sizeof(uint16_t)); other_groupnum = net_ntohs(other_groupnum); - int friendcon_id = getfriendcon_id(m, friendnumber); + const int friendcon_id = getfriendcon_id(m, friendnumber); + + if (friendcon_id == -1) { + // TODO(iphydf): Log something? + return; + } + uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE], temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; get_friendcon_public_keys(real_pk, temp_pk, g_c->fr_c, friendcon_id);