From 3030cda47e3417c123fc62187ea7317bf86a11eb Mon Sep 17 00:00:00 2001 From: jfreegman Date: Fri, 10 Dec 2021 13:44:33 -0500 Subject: [PATCH] Fix possible null dereference game invite info needs to be set after calloc in case it fails --- src/chat.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/chat.c b/src/chat.c index 3e4caea..241cb34 100644 --- a/src/chat.c +++ b/src/chat.c @@ -798,12 +798,7 @@ void chat_onGameInvite(ToxWindow *self, Tox *m, uint32_t friend_number, const ui return; } - Friends.list[friend_number].game_invite.type = type; - Friends.list[friend_number].game_invite.id = id; - Friends.list[friend_number].game_invite.pending = true; - uint32_t data_length = length - GAME_PACKET_HEADER_SIZE; - Friends.list[friend_number].game_invite.data_length = data_length; if (data_length > 0) { free(Friends.list[friend_number].game_invite.data); @@ -818,6 +813,11 @@ void chat_onGameInvite(ToxWindow *self, Tox *m, uint32_t friend_number, const ui Friends.list[friend_number].game_invite.data = buf; } + Friends.list[friend_number].game_invite.type = type; + Friends.list[friend_number].game_invite.id = id; + Friends.list[friend_number].game_invite.pending = true; + Friends.list[friend_number].game_invite.data_length = data_length; + char name[TOX_MAX_NAME_LENGTH]; get_nick_truncate(m, name, friend_number);