summaryrefslogtreecommitdiff
path: root/toxcore/onion.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-12-31 15:24:09 -0500
committerirungentoo <irungentoo@gmail.com>2014-12-31 15:24:09 -0500
commit8ac13beea427cd1bf321bf89adcda51ace66bf1d (patch)
tree393607fe3eaec30dd31bfc3fd2cb007372714c3e /toxcore/onion.c
parent4c8737785adb38991cbea56b35a16f45189020ba (diff)
Code cleanup.
Added length checks to ipport_pack() function.
Diffstat (limited to 'toxcore/onion.c')
-rw-r--r--toxcore/onion.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/toxcore/onion.c b/toxcore/onion.c
index 1ce8146e..b444e02a 100644
--- a/toxcore/onion.c
+++ b/toxcore/onion.c
@@ -293,7 +293,9 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port
293 return 1; 293 return 1;
294 294
295 IP_Port send_to; 295 IP_Port send_to;
296 ipport_unpack(&send_to, plain); 296
297 if (ipport_unpack(&send_to, plain, len) == -1)
298 return 1;
297 299
298 if (to_host_family(&send_to.ip) == -1) 300 if (to_host_family(&send_to.ip) == -1)
299 return 1; 301 return 1;
@@ -344,7 +346,9 @@ static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, ui
344 return 1; 346 return 1;
345 347
346 IP_Port send_to; 348 IP_Port send_to;
347 ipport_unpack(&send_to, plain); 349
350 if (ipport_unpack(&send_to, plain, len) == -1)
351 return 1;
348 352
349 if (to_host_family(&send_to.ip) == -1) 353 if (to_host_family(&send_to.ip) == -1)
350 return 1; 354 return 1;
@@ -395,7 +399,9 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui
395 return 1; 399 return 1;
396 400
397 IP_Port send_to; 401 IP_Port send_to;
398 ipport_unpack(&send_to, plain); 402
403 if (ipport_unpack(&send_to, plain, len) == -1)
404 return 1;
399 405
400 if (to_host_family(&send_to.ip) == -1) 406 if (to_host_family(&send_to.ip) == -1)
401 return 1; 407 return 1;
@@ -443,7 +449,9 @@ static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, ui
443 return 1; 449 return 1;
444 450
445 IP_Port send_to; 451 IP_Port send_to;
446 ipport_unpack(&send_to, plain); 452
453 if (ipport_unpack(&send_to, plain, len) == -1)
454 return 1;
447 455
448 uint8_t data[ONION_MAX_PACKET_SIZE]; 456 uint8_t data[ONION_MAX_PACKET_SIZE];
449 data[0] = NET_PACKET_ONION_RECV_2; 457 data[0] = NET_PACKET_ONION_RECV_2;
@@ -477,7 +485,9 @@ static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, ui
477 return 1; 485 return 1;
478 486
479 IP_Port send_to; 487 IP_Port send_to;
480 ipport_unpack(&send_to, plain); 488
489 if (ipport_unpack(&send_to, plain, len) == -1)
490 return 1;
481 491
482 uint8_t data[ONION_MAX_PACKET_SIZE]; 492 uint8_t data[ONION_MAX_PACKET_SIZE];
483 data[0] = NET_PACKET_ONION_RECV_1; 493 data[0] = NET_PACKET_ONION_RECV_1;
@@ -511,7 +521,9 @@ static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, ui
511 return 1; 521 return 1;
512 522
513 IP_Port send_to; 523 IP_Port send_to;
514 ipport_unpack(&send_to, plain); 524
525 if (ipport_unpack(&send_to, plain, len) == -1)
526 return 1;
515 527
516 uint16_t data_len = length - (1 + RETURN_1); 528 uint16_t data_len = length - (1 + RETURN_1);
517 529