diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/Messenger.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index 33af599d..b29bd1f1 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -215,17 +215,15 @@ uint32_t m_sendmessage_withid(int friendnumber, uint32_t theid, uint8_t *message | |||
215 | { | 215 | { |
216 | if (friendnumber < 0 || friendnumber >= numfriends) | 216 | if (friendnumber < 0 || friendnumber >= numfriends) |
217 | return 0; | 217 | return 0; |
218 | if (length >= (MAX_DATA_SIZE - 4) || friendlist[friendnumber].status != FRIEND_ONLINE) | 218 | if (length >= (MAX_DATA_SIZE - sizeof(theid)) || friendlist[friendnumber].status != FRIEND_ONLINE) |
219 | /* this does not mean the maximum message length is MAX_DATA_SIZE - 1, it is actually 17 bytes less. */ | 219 | /* this does not mean the maximum message length is MAX_DATA_SIZE - 1, it is actually 17 bytes less. */ |
220 | return 0; | 220 | return 0; |
221 | uint8_t temp[MAX_DATA_SIZE]; | 221 | uint8_t temp[MAX_DATA_SIZE]; |
222 | temp[0] = PACKET_ID_MESSAGE; | 222 | temp[0] = PACKET_ID_MESSAGE; |
223 | temp[1] = theid >> 24; | 223 | theid = htonl(theid); |
224 | temp[2] = theid >> 16; | 224 | memcpy(temp + 1, &theid, sizeof(theid)); |
225 | temp[3] = theid >> 8; | 225 | memcpy(temp + 1 + sizeof(theid), message, length); |
226 | temp[4] = theid; | 226 | return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1 + sizeof(theid)); |
227 | memcpy(temp + 5, message, length); | ||
228 | return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 5); | ||
229 | } | 227 | } |
230 | 228 | ||
231 | /* send a name packet to friendnumber | 229 | /* send a name packet to friendnumber |
@@ -397,7 +395,7 @@ static void set_friend_userstatus_kind(int friendnumber, USERSTATUS_KIND k) | |||
397 | /* Sets whether we send read receipts for friendnumber. */ | 395 | /* Sets whether we send read receipts for friendnumber. */ |
398 | void m_set_sends_receipts(int friendnumber, int yesno) | 396 | void m_set_sends_receipts(int friendnumber, int yesno) |
399 | { | 397 | { |
400 | if (yesno < 0 || yesno > 1) | 398 | if (yesno != 0 || yesno != 1) |
401 | return; | 399 | return; |
402 | if (friendnumber >= numfriends || friendnumber < 0) | 400 | if (friendnumber >= numfriends || friendnumber < 0) |
403 | return; | 401 | return; |
@@ -549,9 +547,11 @@ static void doFriends(void) | |||
549 | break; | 547 | break; |
550 | } | 548 | } |
551 | case PACKET_ID_RECEIPT: { | 549 | case PACKET_ID_RECEIPT: { |
552 | if (len < 5) | 550 | uint32_t msgid; |
551 | if (len < 1 + sizeof(msgid)) | ||
553 | break; | 552 | break; |
554 | uint32_t msgid = (temp[1] << 24) | (temp[2] << 16) | (temp[3] << 8) | temp[4]; | 553 | memcpy(&msgid, temp + 1, sizeof(msgid)); |
554 | msgid = ntohl(msgid); | ||
555 | if (read_receipt_isset) | 555 | if (read_receipt_isset) |
556 | (*read_receipt)(i, msgid); | 556 | (*read_receipt)(i, msgid); |
557 | break; | 557 | break; |