From: Tobias Brunner Date: Fri, 20 Oct 2023 14:40:38 +0000 (+0200) Subject: traffic-selector: Make `net` optional in to_subnet() to determine just the mask X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54388bdb8663c9122fea702ce834a8bc5fc4b34f;p=thirdparty%2Fstrongswan.git traffic-selector: Make `net` optional in to_subnet() to determine just the mask --- diff --git a/src/libstrongswan/selectors/traffic_selector.c b/src/libstrongswan/selectors/traffic_selector.c index fe61e3768b..1f5021f0e1 100644 --- a/src/libstrongswan/selectors/traffic_selector.c +++ b/src/libstrongswan/selectors/traffic_selector.c @@ -607,23 +607,25 @@ METHOD(traffic_selector_t, to_subnet, bool, return FALSE; } - net_chunk.ptr = malloc(net_chunk.len); - memset(net_chunk.ptr, 0x00, net_chunk.len); - if (*mask) - { - non_zero_bytes = (*mask + 7) / 8; - memcpy(net_chunk.ptr, this->from, non_zero_bytes); - net_chunk.ptr[non_zero_bytes-1] &= 0xFF << (8 * non_zero_bytes - *mask); - } - - if (this->to_port == this->from_port) + if (net) { - port = this->to_port; - } + net_chunk.ptr = malloc(net_chunk.len); + memset(net_chunk.ptr, 0x00, net_chunk.len); + if (*mask) + { + non_zero_bytes = (*mask + 7) / 8; + memcpy(net_chunk.ptr, this->from, non_zero_bytes); + net_chunk.ptr[non_zero_bytes-1] &= 0xFF << (8 * non_zero_bytes - *mask); + } - *net = host_create_from_chunk(family, net_chunk, port); - chunk_free(&net_chunk); + if (this->to_port == this->from_port) + { + port = this->to_port; + } + *net = host_create_from_chunk(family, net_chunk, port); + chunk_free(&net_chunk); + } return this->netbits != NON_SUBNET_ADDRESS_RANGE; }