From 157d8cfd6a467a44ae0145ed8007819c3e3d2660 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Fri, 25 Oct 2019 17:46:49 +0100 Subject: [PATCH] Don't silently discard all-zeroes adddresses in --host-record. --- src/cache.c | 4 ++-- src/dnsmasq.h | 4 +++- src/option.c | 13 ++++++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/cache.c b/src/cache.c index 733e053..ec193b9 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1290,7 +1290,7 @@ void cache_reload(void) for (hr = daemon->host_records; hr; hr = hr->next) for (nl = hr->names; nl; nl = nl->next) { - if (hr->addr.s_addr != 0 && + if ((hr->flags & HR_4) && (cache = whine_malloc(SIZEOF_POINTER_CREC))) { cache->name.namep = nl->name; @@ -1299,7 +1299,7 @@ void cache_reload(void) add_hosts_entry(cache, (union all_addr *)&hr->addr, INADDRSZ, SRC_CONFIG, (struct crec **)daemon->packet, revhashsz); } - if (!IN6_IS_ADDR_UNSPECIFIED(&hr->addr6) && + if ((hr->flags & HR_6) && (cache = whine_malloc(SIZEOF_POINTER_CREC))) { cache->name.namep = nl->name; diff --git a/src/dnsmasq.h b/src/dnsmasq.h index 149739d..e78afd3 100644 --- a/src/dnsmasq.h +++ b/src/dnsmasq.h @@ -397,9 +397,11 @@ struct auth_zone { struct auth_zone *next; }; +#define HR_6 1 +#define HR_4 2 struct host_record { - int ttl; + int ttl, flags; struct name_list { char *name; struct name_list *next; diff --git a/src/option.c b/src/option.c index 7ca851d..0e9b305 100644 --- a/src/option.c +++ b/src/option.c @@ -4321,6 +4321,7 @@ err: new = opt_malloc(sizeof(struct host_record)); memset(new, 0, sizeof(struct host_record)); new->ttl = -1; + new->flags = 0; while (arg) { @@ -4333,9 +4334,15 @@ err: if (*dig == 0) new->ttl = atoi(arg); else if (inet_pton(AF_INET, arg, &addr.addr4)) - new->addr = addr.addr4; + { + new->addr = addr.addr4; + new->flags |= HR_4; + } else if (inet_pton(AF_INET6, arg, &addr.addr6)) - new->addr6 = addr.addr6; + { + new->addr6 = addr.addr6; + new->flags |= HR_6; + } else { int nomem; @@ -5083,7 +5090,7 @@ void read_opts(int argc, char **argv, char *compile_opts) #define NOLOOP 1 #define TESTLOOP 2 - /* Fill in TTL for CNAMES noe we have local_ttl. + /* Fill in TTL for CNAMES now we have local_ttl. Also prepare to do loop detection. */ for (cn = daemon->cnames; cn; cn = cn->next) {