check length of name

This commit is contained in:
Jfreegman 2013-09-23 15:40:25 -04:00
parent c4702985a5
commit 23e03b0ba9
2 changed files with 6 additions and 0 deletions

View File

@ -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;

View File

@ -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.