Fix caching bug with negative records.

To provoke this bug, at least the following must be true.

A reply must be a CNAME.
The target of the CNAME must not exist for the queried RR (a No Data reply).
The No Data reply must include an SOA record in the NS section.
The query must take place over TCP.

The result is the caching of a CNAME whose target is the
name of the SOA record, instead of the No data record.

If there is a RR at this target, then a subsequent query for that
RRtype will get a qrong reply.

Thanks to the testers extraordinaire at Pi-Hole for spotting this
and providing enough information to chase it down.
This commit is contained in:
Simon Kelley
2025-08-10 23:32:59 +01:00
parent c91c66ee63
commit ff30fa4b91
2 changed files with 24 additions and 11 deletions

View File

@@ -938,15 +938,14 @@ int cache_recv_insert(time_t now, int fd)
if (newc)
{
newc->addr.cname.is_name_ptr = 0;
newc->addr.cname.target.cache = crecp;
if (!crecp)
newc->addr.cname.target.cache = NULL;
else
if (crecp)
{
next_uid(crecp);
newc->addr.cname.target.cache = crecp;
newc->addr.cname.uid = crecp->uid;
}
crecp = newc;
}
}
else