[9.20] fix: dev: Fix a possible crash when adding a zone while recursing

A query for a zone that was not yet loaded may yield an unexpected result such as a CNAME or DNAME, triggering an assertion failure. This has been fixed.

Closes #5357

Backport of MR !10562

Merge branch 'backport-5357-resume-qmin-cname-9.20' into 'bind-9.20'

See merge request isc-projects/bind9!10718
This commit is contained in:
Mark Andrews 2025-07-09 11:43:30 +10:00
commit 7a3ec8dd94

View file

@ -107,6 +107,14 @@
DNS_LOGMODULE_RESOLVER, ISC_LOG_DEBUG(3), \
"fctx %p(%s): %s %s%u", fctx, fctx->info, (m1), (m2), \
(v))
#define FCTXTRACEN(m1, name, res) \
do { \
if (isc_log_wouldlog(dns_lctx, ISC_LOG_DEBUG(3))) { \
char dbuf[DNS_NAME_FORMATSIZE]; \
dns_name_format((name), dbuf, sizeof(dbuf)); \
FCTXTRACE4((m1), dbuf, (res)); \
} \
} while (0)
#define FTRACE(m) \
isc_log_write(dns_lctx, DNS_LOGCATEGORY_RESOLVER, \
DNS_LOGMODULE_RESOLVER, ISC_LOG_DEBUG(3), \
@ -158,6 +166,7 @@
UNUSED(m2); \
UNUSED(v); \
} while (0)
#define FCTXTRACEN(m1, name, res) FCTXTRACE4(m1, name, res)
#define FTRACE(m) \
do { \
UNUSED(m); \
@ -4265,13 +4274,20 @@ resume_qmin(void *arg) {
result = dns_view_findzonecut(res->view, fctx->name, fname, dcname,
fctx->now, findoptions, true, true,
&fctx->nameservers, NULL);
FCTXTRACEN("resume_qmin findzonecut", fname, result);
/*
* DNS_R_NXDOMAIN here means we have not loaded the root zone
* mirror yet - but DNS_R_NXDOMAIN is not a valid return value
* when doing recursion, we need to patch it.
*
* CNAME or DNAME means zone were added with that record
* after the start of a recursion. It means we do not have
* initialized correct hevent->foundname and have to fail.
*/
if (result == DNS_R_NXDOMAIN) {
if (result == DNS_R_NXDOMAIN || result == DNS_R_CNAME ||
result == DNS_R_DNAME)
{
result = DNS_R_SERVFAIL;
}
@ -5004,6 +5020,8 @@ clone_results(fetchctx_t *fctx) {
/* This is the head resp; keep a pointer and move on */
if (hresp == NULL) {
hresp = ISC_LIST_HEAD(fctx->resps);
FCTXTRACEN("clone_results", hresp->foundname,
hresp->result);
continue;
}