All strings should now be forced terminated when received.

This commit is contained in:
irungentoo 2014-02-12 13:14:25 -05:00
parent 95dd3dfdde
commit 704c27c66c
3 changed files with 10 additions and 2 deletions

View File

@ -821,6 +821,8 @@ static void group_message_function(Group_Chat *chat, int peer_number, uint8_t *m
if (i == -1)
return;
message[length - 1] = 0; /* Force NULL terminator */
if (m->group_message)
(*m->group_message)(m, i, peer_number, message, length, m->group_message_userdata);
}
@ -833,6 +835,8 @@ static void group_action_function(Group_Chat *chat, int peer_number, uint8_t *ac
if (i == -1)
return;
action[length - 1] = 0; /* Force NULL terminator */
if (m->group_action)
(*m->group_action)(m, i, peer_number, action, length, m->group_action_userdata);
}
@ -1848,6 +1852,8 @@ void do_friends(Messenger *m)
m->friendlist[i].file_receiving[filenumber].size = filesize;
m->friendlist[i].file_receiving[filenumber].transferred = 0;
data[data_length - 1] = 0; /* Force NULL terminate file name. */
if (m->file_sendrequest)
(*m->file_sendrequest)(m, i, filenumber, filesize, data + 1 + sizeof(uint64_t), data_length - 1 - sizeof(uint64_t),
m->file_sendrequest_userdata);

View File

@ -140,6 +140,9 @@ static int friendreq_handlepacket(void *object, uint8_t *source_pubkey, uint8_t
return 1;
addto_receivedlist(fr, source_pubkey);
packet[length - 1] = 0; /* Force NULL terminator. */
(*fr->handle_friendrequest)(source_pubkey, packet + 4, length - 4, fr->handle_friendrequest_userdata);
return 0;
}

View File

@ -132,8 +132,7 @@ typedef struct Tox Tox;
*
* The length when passing those strings to the core includes that NULL character.
*
* It wont do anything if you send you send non NULL terminated strings because Tox force NULL terminates them anyways
* when it receives them.
* If you send non NULL terminated strings Tox will force NULL terminates them when it receives them.
*/
/* return TOX_FRIEND_ADDRESS_SIZE byte address to give to others.