dnsforward/ipset: rewrite ipset tests to check dnsmasq behavior

In the process, found a segfault from assuming the Res field of proxyCtx
is non-nil. I added a defensive check as I'm not sure if it's guaranteed to be
non-nil in regular execution in this context.
This commit is contained in:
David Sheets
2020-10-06 16:39:34 +01:00
parent 042171d1a1
commit 2db79bf7ec
2 changed files with 162 additions and 25 deletions

View File

@@ -122,15 +122,17 @@ func (c *ipsetCtx) processMembers(ctx *dnsContext, addMember func(string, string
log.Debug("IPSET: found ipsets %v for host %s", ipsetNames, host)
for _, it := range ctx.proxyCtx.Res.Answer {
ip := c.getIP(it)
if ip == nil {
continue
}
if ctx.proxyCtx.Res != nil {
for _, it := range ctx.proxyCtx.Res.Answer {
ip := c.getIP(it)
if ip == nil {
continue
}
ipStr := ip.String()
for _, name := range ipsetNames {
addMember(host, name, ipStr)
ipStr := ip.String()
for _, name := range ipsetNames {
addMember(host, name, ipStr)
}
}
}