From 704c27c66cadf1e5dd81da007ec81874acb699c0 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 12 Feb 2014 13:14:25 -0500 Subject: All strings should now be forced terminated when received. --- toxcore/Messenger.c | 6 ++++++ toxcore/friend_requests.c | 3 +++ toxcore/tox.h | 3 +-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 3b09baa2..fef2e9e5 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -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); diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c index 5c294c76..9ac72097 100644 --- a/toxcore/friend_requests.c +++ b/toxcore/friend_requests.c @@ -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; } diff --git a/toxcore/tox.h b/toxcore/tox.h index 75e1a303..447a1146 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -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. -- cgit v1.2.3