Check if received ip family is valid for the onion packets.

This commit is contained in:
irungentoo 2014-12-31 12:30:39 -05:00
parent 523cc20eb0
commit 8ff85f09cb
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
3 changed files with 20 additions and 7 deletions

View File

@ -164,12 +164,17 @@ void to_net_family(IP *ip)
ip->family = TOX_AF_INET6;
}
void to_host_family(IP *ip)
int to_host_family(IP *ip)
{
if (ip->family == TOX_AF_INET)
if (ip->family == TOX_AF_INET) {
ip->family = AF_INET;
else if (ip->family == TOX_AF_INET6)
return 0;
} else if (ip->family == TOX_AF_INET6) {
ip->family = AF_INET6;
return 0;
} else {
return -1;
}
}
/* Pack number of nodes into data of maxlength length.

View File

@ -65,7 +65,9 @@
/* Functions to transfer ips safely across wire. */
void to_net_family(IP *ip);
void to_host_family(IP *ip);
/* return 0 on success, -1 on failure. */
int to_host_family(IP *ip);
typedef struct {
IP_Port ip_port;

View File

@ -294,7 +294,9 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port
IP_Port send_to;
ipport_unpack(&send_to, plain);
to_host_family(&send_to.ip);
if (to_host_family(&send_to.ip) == -1)
return 1;
uint8_t ip_port[SIZE_IPPORT];
ipport_pack(ip_port, &source);
@ -343,7 +345,9 @@ static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, ui
IP_Port send_to;
ipport_unpack(&send_to, plain);
to_host_family(&send_to.ip);
if (to_host_family(&send_to.ip) == -1)
return 1;
uint8_t data[ONION_MAX_PACKET_SIZE];
data[0] = NET_PACKET_ONION_SEND_2;
@ -392,7 +396,9 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui
IP_Port send_to;
ipport_unpack(&send_to, plain);
to_host_family(&send_to.ip);
if (to_host_family(&send_to.ip) == -1)
return 1;
uint8_t data[ONION_MAX_PACKET_SIZE];
memcpy(data, plain + SIZE_IPPORT, len - SIZE_IPPORT);