summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Derigs <dl6er@dl6er.de>2022-10-16 22:30:08 +0100
committerSimon Kelley <simon@thekelleys.org.uk>2022-10-16 22:30:08 +0100
commit936be022d956882c3a980d15e8fa70f8858751d9 (patch)
treecc7aab28107ac068951815120546340b22805bde
parent0017dd74d519d6d963fb8c0b4f07e69e55a46a13 (diff)
downloaddnsmasq-936be022d956882c3a980d15e8fa70f8858751d9.tar.gz
Handle multiple addresses when removing duplicates in host files.
-rw-r--r--src/cache.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/cache.c b/src/cache.c
index 7cb5221..35df2d0 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -1048,16 +1048,17 @@ struct crec *cache_find_by_addr(struct crec *crecp, union all_addr *addr,
static void add_hosts_entry(struct crec *cache, union all_addr *addr, int addrlen,
unsigned int index, struct crec **rhash, int hashsz)
{
- struct crec *lookup = cache_find_by_name(NULL, cache_get_name(cache), 0, cache->flags & (F_IPV4 | F_IPV6));
int i;
unsigned int j;
+ struct crec *lookup = NULL;
/* Remove duplicates in hosts files. */
- if (lookup && (lookup->flags & F_HOSTS) && memcmp(&lookup->addr, addr, addrlen) == 0)
- {
- free(cache);
- return;
- }
+ while ((lookup = cache_find_by_name(lookup, cache_get_name(cache), 0, cache->flags & (F_IPV4 | F_IPV6))))
+ if ((lookup->flags & F_HOSTS) && memcmp(&lookup->addr, addr, addrlen) == 0)
+ {
+ free(cache);
+ return;
+ }
/* Ensure there is only one address -> name mapping (first one trumps)
We do this by steam here, The entries are kept in hash chains, linked