From 413933a846f5648f2329ee82d5f7bf9add496804 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 3 Apr 2014 20:21:24 -0400 Subject: [PATCH] Maximum name lengths should now be the real maximum and not one byte less. --- toxcore/Messenger.c | 4 ++-- toxcore/group_chats.c | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 4e427a25..db5390c0 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -1934,7 +1934,7 @@ void do_friends(Messenger *m) } case PACKET_ID_NICKNAME: { - if (data_length >= MAX_NAME_LENGTH || data_length == 0) + if (data_length > MAX_NAME_LENGTH || data_length == 0) break; /* Make sure the NULL terminator is present. */ @@ -1946,7 +1946,7 @@ void do_friends(Messenger *m) if (m->friend_namechange) m->friend_namechange(m, i, data_terminated, data_length, m->friend_namechange_userdata); - memcpy(m->friendlist[i].name, data_terminated, data_length + 1); + memcpy(m->friendlist[i].name, data_terminated, data_length); m->friendlist[i].name_length = data_length; break; diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index 58ec156b..de39331e 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c @@ -335,7 +335,7 @@ int group_peername(Group_Chat *chat, int peernum, uint8_t *name) static void setnick(Group_Chat *chat, int peernum, uint8_t *contents, uint16_t contents_len) { - if (contents_len >= MAX_NICK_BYTES || contents_len == 0) + if (contents_len > MAX_NICK_BYTES || contents_len == 0) return; /* same name as already stored? */ @@ -344,8 +344,6 @@ static void setnick(Group_Chat *chat, int peernum, uint8_t *contents, uint16_t c return; memcpy(chat->group[peernum].nick, contents, contents_len); - /* Force null termination */ - chat->group[peernum].nick[contents_len] = 0; chat->group[peernum].nick_len = contents_len; if (chat->peer_namelistchange != NULL)