mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Check if received ip family is valid for the onion packets.
This commit is contained in:
parent
523cc20eb0
commit
8ff85f09cb
|
@ -164,12 +164,17 @@ void to_net_family(IP *ip)
|
||||||
ip->family = TOX_AF_INET6;
|
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;
|
ip->family = AF_INET;
|
||||||
else if (ip->family == TOX_AF_INET6)
|
return 0;
|
||||||
|
} else if (ip->family == TOX_AF_INET6) {
|
||||||
ip->family = AF_INET6;
|
ip->family = AF_INET6;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pack number of nodes into data of maxlength length.
|
/* Pack number of nodes into data of maxlength length.
|
||||||
|
|
|
@ -65,7 +65,9 @@
|
||||||
|
|
||||||
/* Functions to transfer ips safely across wire. */
|
/* Functions to transfer ips safely across wire. */
|
||||||
void to_net_family(IP *ip);
|
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 {
|
typedef struct {
|
||||||
IP_Port ip_port;
|
IP_Port ip_port;
|
||||||
|
|
|
@ -294,7 +294,9 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port
|
||||||
|
|
||||||
IP_Port send_to;
|
IP_Port send_to;
|
||||||
ipport_unpack(&send_to, plain);
|
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];
|
uint8_t ip_port[SIZE_IPPORT];
|
||||||
ipport_pack(ip_port, &source);
|
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;
|
IP_Port send_to;
|
||||||
ipport_unpack(&send_to, plain);
|
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];
|
uint8_t data[ONION_MAX_PACKET_SIZE];
|
||||||
data[0] = NET_PACKET_ONION_SEND_2;
|
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;
|
IP_Port send_to;
|
||||||
ipport_unpack(&send_to, plain);
|
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];
|
uint8_t data[ONION_MAX_PACKET_SIZE];
|
||||||
memcpy(data, plain + SIZE_IPPORT, len - SIZE_IPPORT);
|
memcpy(data, plain + SIZE_IPPORT, len - SIZE_IPPORT);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user