Skip to content

Commit 7edc0a5

Browse files
committed
Bound the number of friends you can have to ~4 billion.
If you have UINT32_MAX friends, then adding one more friend will cause an overflow of the friend list (wrap to 0) and result in all friends being deleted. This subsequently results in a null pointer dereference when we're trying to add one friend to the deleted friend list.
1 parent de3c21b commit 7edc0a5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

toxcore/Messenger.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ static int m_handle_lossy_packet(void *object, int friend_num, const uint8_t *pa
161161

162162
static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status)
163163
{
164+
if (m->numfriends == UINT32_MAX) {
165+
LOGGER_ERROR(m->log, "Friend list full: we have more than 4 billion friends");
166+
/* This is technically incorrect, but close enough. */
167+
return FAERR_NOMEM;
168+
}
169+
164170
/* Resize the friend list if necessary. */
165171
if (realloc_friendlist(m, m->numfriends + 1) != 0) {
166172
return FAERR_NOMEM;

0 commit comments

Comments
 (0)