summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-02-16 20:25:44 -0500
committerirungentoo <irungentoo@gmail.com>2015-02-16 20:25:44 -0500
commit8532dc8ae71396a3b7f0731d585c086d180e7e5f (patch)
tree0314b7b05d754a830a5c100bd569e030fd126aa4 /toxcore
parent7e2839e2d8f16f72143a9c405b5a410a11489eb3 (diff)
Allow empty names and status messages.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c35
-rw-r--r--toxcore/Messenger.h2
-rw-r--r--toxcore/group.c8
3 files changed, 25 insertions, 20 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 194a633e..1bcc1f51 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -204,8 +204,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta
204 m->friendlist[i].friendcon_id = friendcon_id; 204 m->friendlist[i].friendcon_id = friendcon_id;
205 m->friendlist[i].friendrequest_lastsent = 0; 205 m->friendlist[i].friendrequest_lastsent = 0;
206 id_copy(m->friendlist[i].real_pk, real_pk); 206 id_copy(m->friendlist[i].real_pk, real_pk);
207 m->friendlist[i].statusmessage = calloc(1, 1); 207 m->friendlist[i].statusmessage_length = 0;
208 m->friendlist[i].statusmessage_length = 1;
209 m->friendlist[i].userstatus = USERSTATUS_NONE; 208 m->friendlist[i].userstatus = USERSTATUS_NONE;
210 m->friendlist[i].avatar_info_sent = 0; 209 m->friendlist[i].avatar_info_sent = 0;
211 m->friendlist[i].avatar_recv_data = NULL; 210 m->friendlist[i].avatar_recv_data = NULL;
@@ -334,7 +333,6 @@ int m_delfriend(Messenger *m, int32_t friendnumber)
334 if (m->friendlist[friendnumber].status == FRIEND_ONLINE) 333 if (m->friendlist[friendnumber].status == FRIEND_ONLINE)
335 remove_online_friend(m, friendnumber); 334 remove_online_friend(m, friendnumber);
336 335
337 free(m->friendlist[friendnumber].statusmessage);
338 free(m->friendlist[friendnumber].avatar_recv_data); 336 free(m->friendlist[friendnumber].avatar_recv_data);
339 remove_request_received(&(m->fr), m->friendlist[friendnumber].real_pk); 337 remove_request_received(&(m->fr), m->friendlist[friendnumber].real_pk);
340 friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, 0, 0, 0, 0, 0); 338 friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, 0, 0, 0, 0, 0);
@@ -451,7 +449,7 @@ uint32_t m_sendaction_withid(const Messenger *m, int32_t friendnumber, uint32_t
451 */ 449 */
452static int m_sendname(const Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length) 450static int m_sendname(const Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length)
453{ 451{
454 if (length > MAX_NAME_LENGTH || length == 0) 452 if (length > MAX_NAME_LENGTH)
455 return 0; 453 return 0;
456 454
457 return write_cryptpacket_id(m, friendnumber, PACKET_ID_NICKNAME, name, length, 0); 455 return write_cryptpacket_id(m, friendnumber, PACKET_ID_NICKNAME, name, length, 0);
@@ -485,13 +483,15 @@ int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint1
485 */ 483 */
486int setname(Messenger *m, const uint8_t *name, uint16_t length) 484int setname(Messenger *m, const uint8_t *name, uint16_t length)
487{ 485{
488 if (length > MAX_NAME_LENGTH || length == 0) 486 if (length > MAX_NAME_LENGTH)
489 return -1; 487 return -1;
490 488
491 if (m->name_length == length && memcmp(name, m->name, length) == 0) 489 if (m->name_length == length && (length == 0 || memcmp(name, m->name, length) == 0))
492 return 0; 490 return 0;
493 491
494 memcpy(m->name, name, length); 492 if (length)
493 memcpy(m->name, name, length);
494
495 m->name_length = length; 495 m->name_length = length;
496 uint32_t i; 496 uint32_t i;
497 497
@@ -550,10 +550,12 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length)
550 if (length > MAX_STATUSMESSAGE_LENGTH) 550 if (length > MAX_STATUSMESSAGE_LENGTH)
551 return -1; 551 return -1;
552 552
553 if (m->statusmessage_length == length && memcmp(m->statusmessage, status, length) == 0) 553 if (m->statusmessage_length == length && (length == 0 || memcmp(m->statusmessage, status, length) == 0))
554 return 0; 554 return 0;
555 555
556 memcpy(m->statusmessage, status, length); 556 if (length)
557 memcpy(m->statusmessage, status, length);
558
557 m->statusmessage_length = length; 559 m->statusmessage_length = length;
558 560
559 uint32_t i; 561 uint32_t i;
@@ -859,10 +861,12 @@ static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, co
859 if (friend_not_valid(m, friendnumber)) 861 if (friend_not_valid(m, friendnumber))
860 return -1; 862 return -1;
861 863
862 uint8_t *newstatus = calloc(length + 1, 1); 864 if (length > MAX_STATUSMESSAGE_LENGTH)
863 memcpy(newstatus, status, length); 865 return -1;
864 free(m->friendlist[friendnumber].statusmessage); 866
865 m->friendlist[friendnumber].statusmessage = newstatus; 867 if (length)
868 memcpy(m->friendlist[friendnumber].statusmessage, status, length);
869
866 m->friendlist[friendnumber].statusmessage_length = length; 870 m->friendlist[friendnumber].statusmessage_length = length;
867 return 0; 871 return 0;
868} 872}
@@ -1632,7 +1636,6 @@ void kill_messenger(Messenger *m)
1632 kill_networking(m->net); 1636 kill_networking(m->net);
1633 1637
1634 for (i = 0; i < m->numfriends; ++i) { 1638 for (i = 0; i < m->numfriends; ++i) {
1635 free(m->friendlist[i].statusmessage);
1636 free(m->friendlist[i].avatar_recv_data); 1639 free(m->friendlist[i].avatar_recv_data);
1637 } 1640 }
1638 1641
@@ -1990,7 +1993,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
1990 } 1993 }
1991 1994
1992 case PACKET_ID_NICKNAME: { 1995 case PACKET_ID_NICKNAME: {
1993 if (data_length > MAX_NAME_LENGTH || data_length == 0) 1996 if (data_length > MAX_NAME_LENGTH)
1994 break; 1997 break;
1995 1998
1996 /* Make sure the NULL terminator is present. */ 1999 /* Make sure the NULL terminator is present. */
@@ -2009,7 +2012,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
2009 } 2012 }
2010 2013
2011 case PACKET_ID_STATUSMESSAGE: { 2014 case PACKET_ID_STATUSMESSAGE: {
2012 if (data_length == 0 || data_length > MAX_STATUSMESSAGE_LENGTH) 2015 if (data_length > MAX_STATUSMESSAGE_LENGTH)
2013 break; 2016 break;
2014 2017
2015 /* Make sure the NULL terminator is present. */ 2018 /* Make sure the NULL terminator is present. */
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 367e65c7..91faff66 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -201,7 +201,7 @@ typedef struct {
201 uint8_t name[MAX_NAME_LENGTH]; 201 uint8_t name[MAX_NAME_LENGTH];
202 uint16_t name_length; 202 uint16_t name_length;
203 uint8_t name_sent; // 0 if we didn't send our name to this friend 1 if we have. 203 uint8_t name_sent; // 0 if we didn't send our name to this friend 1 if we have.
204 uint8_t *statusmessage; 204 uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH];
205 uint16_t statusmessage_length; 205 uint16_t statusmessage_length;
206 uint8_t statusmessage_sent; 206 uint8_t statusmessage_sent;
207 USERSTATUS userstatus; 207 USERSTATUS userstatus;
diff --git a/toxcore/group.c b/toxcore/group.c
index c1a60851..786a9cdd 100644
--- a/toxcore/group.c
+++ b/toxcore/group.c
@@ -518,7 +518,7 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index)
518 518
519static int setnick(Group_Chats *g_c, int groupnumber, int peer_index, const uint8_t *nick, uint16_t nick_len) 519static int setnick(Group_Chats *g_c, int groupnumber, int peer_index, const uint8_t *nick, uint16_t nick_len)
520{ 520{
521 if (nick_len > MAX_NAME_LENGTH || nick_len == 0) 521 if (nick_len > MAX_NAME_LENGTH)
522 return -1; 522 return -1;
523 523
524 Group_c *g = get_group_c(g_c, groupnumber); 524 Group_c *g = get_group_c(g_c, groupnumber);
@@ -528,10 +528,12 @@ static int setnick(Group_Chats *g_c, int groupnumber, int peer_index, const uint
528 528
529 /* same name as already stored? */ 529 /* same name as already stored? */
530 if (g->group[peer_index].nick_len == nick_len) 530 if (g->group[peer_index].nick_len == nick_len)
531 if (!memcmp(g->group[peer_index].nick, nick, nick_len)) 531 if (nick_len == 0 || !memcmp(g->group[peer_index].nick, nick, nick_len))
532 return 0; 532 return 0;
533 533
534 memcpy(g->group[peer_index].nick, nick, nick_len); 534 if (nick_len)
535 memcpy(g->group[peer_index].nick, nick, nick_len);
536
535 g->group[peer_index].nick_len = nick_len; 537 g->group[peer_index].nick_len = nick_len;
536 538
537 if (g_c->peer_namelistchange) 539 if (g_c->peer_namelistchange)