3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-26 10:39:23 +01:00

ip-pool: Validate prefix lengths in used addresses

Be paranoid and check that the prefix length in addresses from
used_addr4_list are not zero (they shouldn't be) and that address family
is AF_INET (it should be), mainly to quiet coverity warnings:

While there also fix one line's indentation.
This commit is contained in:
Andrew Zaborowski 2021-06-07 23:26:27 +02:00 committed by Denis Kenzior
parent b1c8a57047
commit c295fba546

View File

@ -149,13 +149,19 @@ int ip_pool_select_addr4(const char **addr_str_list, uint8_t subnet_prefix_len,
const struct ip_pool_addr4_record *rec = entry->data; const struct ip_pool_addr4_record *rec = entry->data;
struct ip_pool_addr4_range *range; struct ip_pool_addr4_range *range;
char addr_str[INET_ADDRSTRLEN]; char addr_str[INET_ADDRSTRLEN];
uint32_t used_subnet_size = 1 << uint8_t used_prefix_len =
(32 - l_rtnl_address_get_prefix_length(rec->addr)); l_rtnl_address_get_prefix_length(rec->addr);
uint32_t used_subnet_size;
if (!l_rtnl_address_get_address(rec->addr, addr_str) || if (l_rtnl_address_get_family(rec->addr) != AF_INET ||
!l_rtnl_address_get_address(rec->addr,
addr_str) ||
used_prefix_len < 1 ||
inet_pton(AF_INET, addr_str, &ia) != 1) inet_pton(AF_INET, addr_str, &ia) != 1)
continue; continue;
used_subnet_size = 1 << (32 - used_prefix_len);
range = l_new(struct ip_pool_addr4_range, 1); range = l_new(struct ip_pool_addr4_range, 1);
range->start = ntohl(ia.s_addr) & subnet_mask; range->start = ntohl(ia.s_addr) & subnet_mask;
range->end = (range->start + used_subnet_size + subnet_size - range->end = (range->start + used_subnet_size + subnet_size -
@ -216,7 +222,7 @@ check_avail:
for (entry = l_queue_get_entries(ranges); entry; entry = entry->next) { for (entry = l_queue_get_entries(ranges); entry; entry = entry->next) {
struct ip_pool_addr4_range *range = entry->data; struct ip_pool_addr4_range *range = entry->data;
total += (range->end - range->start) >> total += (range->end - range->start) >>
(32 - subnet_prefix_len); (32 - subnet_prefix_len);
} }