summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 33d087de..aa7b05bc 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1379,11 +1379,24 @@ int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uin
1379 if (friend_not_valid(m, friendnumber)) 1379 if (friend_not_valid(m, friendnumber))
1380 return -1; 1380 return -1;
1381 1381
1382 if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
1383 return -2;
1384
1385 if (data[0] < PACKET_ID_LOSSY_RANGE_START)
1386 return -3;
1387
1388 if (data[0] >= (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE))
1389 return -3;
1390
1382 if (m->friendlist[friendnumber].status != FRIEND_ONLINE) 1391 if (m->friendlist[friendnumber].status != FRIEND_ONLINE)
1383 return -1; 1392 return -4;
1384 1393
1385 return send_lossy_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, 1394 if (send_lossy_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
1386 m->friendlist[friendnumber].friendcon_id), data, length); 1395 m->friendlist[friendnumber].friendcon_id), data, length) == -1) {
1396 return -5;
1397 } else {
1398 return 0;
1399 }
1387} 1400}
1388 1401
1389static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length) 1402static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length)
@@ -1417,21 +1430,21 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
1417 if (friend_not_valid(m, friendnumber)) 1430 if (friend_not_valid(m, friendnumber))
1418 return -1; 1431 return -1;
1419 1432
1420 if (length == 0) 1433 if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
1421 return -1; 1434 return -2;
1422 1435
1423 if (data[0] < PACKET_ID_LOSSLESS_RANGE_START) 1436 if (data[0] < PACKET_ID_LOSSLESS_RANGE_START)
1424 return -1; 1437 return -3;
1425 1438
1426 if (data[0] >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE)) 1439 if (data[0] >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE))
1427 return -1; 1440 return -3;
1428 1441
1429 if (m->friendlist[friendnumber].status != FRIEND_ONLINE) 1442 if (m->friendlist[friendnumber].status != FRIEND_ONLINE)
1430 return -1; 1443 return -4;
1431 1444
1432 if (write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, 1445 if (write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
1433 m->friendlist[friendnumber].friendcon_id), data, length, 1) == -1) { 1446 m->friendlist[friendnumber].friendcon_id), data, length, 1) == -1) {
1434 return -1; 1447 return -5;
1435 } else { 1448 } else {
1436 return 0; 1449 return 0;
1437 } 1450 }