summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJfreegman <Jfreegman@gmail.com>2013-09-23 15:40:25 -0400
committerJfreegman <Jfreegman@gmail.com>2013-09-23 15:40:25 -0400
commit23e03b0ba94df9640a978529edaf75b412dbf8a2 (patch)
tree50725cc314993b0c82b49af6fa390cac16f57a4e
parentc4702985a502eb80c3eae37f2b5b38fdb7e385e5 (diff)
check length of name
-rw-r--r--toxcore/Messenger.c3
-rw-r--r--toxcore/Messenger.h3
2 files changed, 6 insertions, 0 deletions
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
357 if (friend_not_valid(m, friendnumber)) 357 if (friend_not_valid(m, friendnumber))
358 return -1; 358 return -1;
359 359
360 if (length > MAX_NAME_LENGTH || length == 0)
361 return -1;
362
360 m->friendlist[friendnumber].name_length = length; 363 m->friendlist[friendnumber].name_length = length;
361 memcpy(m->friendlist[friendnumber].name, name, length); 364 memcpy(m->friendlist[friendnumber].name, name, length);
362 return 0; 365 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
247int m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length); 247int m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length);
248 248
249/* Set the name and name_length of a friend. 249/* Set the name and name_length of a friend.
250 * name must be a string of maximum MAX_NAME_LENGTH length.
251 * length must be at least 1 byte.
252 * length is the length of name with the NULL terminator.
250 * 253 *
251 * return 0 if success. 254 * return 0 if success.
252 * return -1 if failure. 255 * return -1 if failure.