From 41ac67cbb218d9d7da4bd7d767b12c03a0096b5b Mon Sep 17 00:00:00 2001 From: Christopher Maynard Date: Sat, 6 Jun 2015 20:04:42 -0400 Subject: [PATCH] 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 Tested-by: Petri Dish Buildbot Reviewed-by: Jeff Morriss Reviewed-by: Anders Broman --- epan/addr_resolv.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) mode change 100644 => 100755 epan/addr_resolv.c diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c old mode 100644 new mode 100755 index 37dd4b1452..c580311b1a --- a/epan/addr_resolv.c +++ b/epan/addr_resolv.c @@ -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); }