traffic-selector: inet_pton is successful only if it returns 1

This commit is contained in:
Martin Willi
2013-05-16 11:01:27 +02:00
parent 2ce403438f
commit 21bade294b
+17 -23
View File
@@ -814,38 +814,32 @@ traffic_selector_t *traffic_selector_create_from_string(
char *from_addr, u_int16_t from_port, char *from_addr, u_int16_t from_port,
char *to_addr, u_int16_t to_port) char *to_addr, u_int16_t to_port)
{ {
private_traffic_selector_t *this = traffic_selector_create(protocol, type, private_traffic_selector_t *this;
from_port, to_port); int family;
switch (type) switch (type)
{ {
case TS_IPV4_ADDR_RANGE: case TS_IPV4_ADDR_RANGE:
if (inet_pton(AF_INET, from_addr, (struct in_addr*)this->from4) < 0) family = AF_INET;
{
free(this);
return NULL;
}
if (inet_pton(AF_INET, to_addr, (struct in_addr*)this->to4) < 0)
{
free(this);
return NULL;
}
break; break;
case TS_IPV6_ADDR_RANGE: case TS_IPV6_ADDR_RANGE:
if (inet_pton(AF_INET6, from_addr, (struct in6_addr*)this->from6) < 0) family = AF_INET6;
{
free(this);
return NULL;
}
if (inet_pton(AF_INET6, to_addr, (struct in6_addr*)this->to6) < 0)
{
free(this);
return NULL;
}
break; break;
default:
return NULL;
} }
this = traffic_selector_create(protocol, type, from_port, to_port);
if (inet_pton(family, from_addr, this->from) != 1 ||
inet_pton(family, to_addr, this->to) != 1)
{
free(this);
return NULL;
}
calc_netbits(this); calc_netbits(this);
return (&this->public); return &this->public;
} }
/* /*