Fix insertion of subnets read from the subnets file: append to the *end* of

the list.

The patch ensures that non-duplicate subnets are appended to the end of the
list rather than as the second element, which if there had been a second
element previously, the memory for it was effectively leaked.

It also allows /32 "subnets", even though arguably the hosts file should be
used instead, but now the test in read_subnets_file() matches the assert in
subnet_entry_set().

Bug: 11247
Change-Id: I54bf1cbb34edfcf410aa634043a377c27091df51
Reviewed-on: https://code.wireshark.org/review/8802
Petri-Dish: Jeff Morriss <jeff.morriss.ws@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Jeff Morriss <jeff.morriss.ws@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Christopher Maynard 2015-06-06 20:04:42 -04:00 committed by Anders Broman
parent e28339e590
commit 41ac67cbb2
1 changed files with 15 additions and 9 deletions

24
epan/addr_resolv.c Normal file → Executable file
View File

@ -2087,8 +2087,8 @@ read_hosts_file (const char *hostspath, gboolean store_entries)
/*
* Add the aliases, too, if there are any.
* XXX - except we only store the last one added. The name
* resolver returns the first name in the hosts file, we should
* too.
* resolver returns the first name in the hosts file, we should
* too.
*/
while ((cp = strtok(NULL, " \t")) != NULL) {
if (is_ipv6) {
@ -2265,7 +2265,7 @@ read_subnets_file (const char *subnetspath)
}
mask_length = atoi(cp2);
if (0 >= mask_length || mask_length > 31) {
if (0 >= mask_length || mask_length > 32) {
continue; /* invalid mask length */
}
@ -2352,13 +2352,19 @@ subnet_entry_set(guint32 subnet_addr, const guint32 mask_length, const gchar* na
}
if (NULL != (tp = entry->subnet_addresses[hash_idx])) {
if (tp->addr == subnet_addr) {
return; /* XXX provide warning that an address was repeated? */
} else {
sub_net_hashipv4_t * new_tp = g_new(sub_net_hashipv4_t, 1);
tp->next = new_tp;
tp = new_tp;
sub_net_hashipv4_t * new_tp;
while (tp->next) {
if (tp->addr == subnet_addr) {
return; /* XXX provide warning that an address was repeated? */
} else {
tp = tp->next;
}
}
new_tp = g_new(sub_net_hashipv4_t, 1);
tp->next = new_tp;
tp = new_tp;
} else {
tp = entry->subnet_addresses[hash_idx] = g_new(sub_net_hashipv4_t, 1);
}