diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 9601f2a2..0efe20ce 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -357,6 +357,9 @@ int setfriendname(Messenger *m, int friendnumber, uint8_t *name, uint16_t length if (friend_not_valid(m, friendnumber)) return -1; + if (length > MAX_NAME_LENGTH || length == 0) + return -1; + m->friendlist[friendnumber].name_length = length; memcpy(m->friendlist[friendnumber].name, name, length); return 0; diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 1f0361b1..0ff14de4 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h @@ -247,6 +247,9 @@ uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, ui int m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length); /* Set the name and name_length of a friend. + * name must be a string of maximum MAX_NAME_LENGTH length. + * length must be at least 1 byte. + * length is the length of name with the NULL terminator. * * return 0 if success. * return -1 if failure.