summaryrefslogtreecommitdiff
path: root/toxcore/network.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/network.c
parent4c8737785adb38991cbea56b35a16f45189020ba (diff)
Code cleanup.
Added length checks to ipport_pack() function.
Diffstat (limited to 'toxcore/network.c')
-rw-r--r--toxcore/network.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/toxcore/network.c b/toxcore/network.c
index 5539de6b..7a528f4f 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -763,10 +763,15 @@ void ip_pack(uint8_t *data, const IP *source)
763 memcpy(data + 1, &source->ip6, SIZE_IP6); 763 memcpy(data + 1, &source->ip6, SIZE_IP6);
764} 764}
765 765
766void ip_unpack(IP *target, const uint8_t *data) 766/* return 0 on success, -1 on failure. */
767int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size)
767{ 768{
769 if (data_size < (1 + SIZE_IP6))
770 return -1;
771
768 target->family = data[0]; 772 target->family = data[0];
769 memcpy(&target->ip6, data + 1, SIZE_IP6); 773 memcpy(&target->ip6, data + 1, SIZE_IP6);
774 return 0;
770} 775}
771 776
772void ipport_pack(uint8_t *data, const IP_Port *source) 777void ipport_pack(uint8_t *data, const IP_Port *source)
@@ -775,10 +780,15 @@ void ipport_pack(uint8_t *data, const IP_Port *source)
775 memcpy(data + SIZE_IP, &source->port, SIZE_PORT); 780 memcpy(data + SIZE_IP, &source->port, SIZE_PORT);
776} 781}
777 782
778void ipport_unpack(IP_Port *target, const uint8_t *data) 783/* return 0 on success, -1 on failure. */
784int ipport_unpack(IP_Port *target, const uint8_t *data, unsigned int data_size)
779{ 785{
780 ip_unpack(&target->ip, data); 786 if (data_size < (SIZE_IP + SIZE_PORT))
787 return -1;
788
789 ip_unpack(&target->ip, data, data_size);
781 memcpy(&target->port, data + SIZE_IP, SIZE_PORT); 790 memcpy(&target->port, data + SIZE_IP, SIZE_PORT);
791 return 0;
782} 792}
783 793
784/* ip_ntoa 794/* ip_ntoa