fixed double free of host in selector2ts

This commit is contained in:
Martin Willi
2008-12-03 09:15:29 +00:00
parent efd0fe21e4
commit 70691c31b2
@@ -423,26 +423,28 @@ static struct xfrm_selector ts2selector(traffic_selector_t *src,
*/ */
static traffic_selector_t* selector2ts(struct xfrm_selector *sel, bool src) static traffic_selector_t* selector2ts(struct xfrm_selector *sel, bool src)
{ {
int family; u_char *addr;
chunk_t addr;
u_int8_t prefixlen; u_int8_t prefixlen;
u_int16_t port, port_mask; u_int16_t port = 0;
host_t *host; host_t *host = NULL;
traffic_selector_t *ts;
if (src) if (src)
{ {
addr.ptr = (u_char*)&sel->saddr; addr = (u_char*)&sel->saddr;
prefixlen = sel->prefixlen_s; prefixlen = sel->prefixlen_s;
port = sel->sport; if (sel->sport_mask)
port_mask = sel->sport_mask; {
port = htons(sel->sport);
}
} }
else else
{ {
addr.ptr = (u_char*)&sel->daddr; addr = (u_char*)&sel->daddr;
prefixlen = sel->prefixlen_d; prefixlen = sel->prefixlen_d;
port = sel->dport; if (sel->dport_mask)
port_mask = sel->dport_mask; {
port = htons(sel->dport);
}
} }
/* The Linux 2.6 kernel does not set the selector's family field, /* The Linux 2.6 kernel does not set the selector's family field,
@@ -450,24 +452,19 @@ static traffic_selector_t* selector2ts(struct xfrm_selector *sel, bool src)
*/ */
if (sel->family == AF_INET || sel->prefixlen_s == 32) if (sel->family == AF_INET || sel->prefixlen_s == 32)
{ {
family = AF_INET; host = host_create_from_chunk(AF_INET, chunk_create(addr, 4), 0);
addr.len = 4;
} }
else if (sel->family == AF_INET6 || sel->prefixlen_s == 128) else if (sel->family == AF_INET6 || sel->prefixlen_s == 128)
{ {
family = AF_INET6; host = host_create_from_chunk(AF_INET6, chunk_create(addr, 16), 0);
addr.len = 16;
} }
else
{
return NULL;
}
host = host_create_from_chunk(family, addr, 0);
port = (port_mask == 0) ? 0 : ntohs(port);
ts = traffic_selector_create_from_subnet(host, prefixlen, sel->proto, port); if (host)
host->destroy(host); {
return ts; return traffic_selector_create_from_subnet(host, prefixlen,
sel->proto, port);
}
return NULL;
} }
/** /**