Fix error path bugs in the "recursing-clients" list management

In two places, after linking the client to the manager's
"recursing-clients" list using the check_recursionquota()
function, the query.c module fails to unlink it on error
paths. Fix the bugs by unlinking the client from the list.

Also make sure that unlinking happens before detaching the
client's handle, as it is the logically correct order, e.g.
in case if it's the last handle and ns__client_reset_cb()
can be called because of the detachment.
This commit is contained in:
Aram Sargsyan
2024-10-02 16:22:38 +00:00
committed by Arаm Sаrgsyаn
parent 84eac93bfd
commit 36c4808903

View File

@@ -6214,12 +6214,20 @@ ns_query_recurse(ns_client_t *client, dns_rdatatype_t qtype, dns_name_t *qname,
0, NULL, client->manager->loop, fetch_callback, client,
rdataset, sigrdataset, &FETCH_RECTYPE_NORMAL(client));
if (result != ISC_R_SUCCESS) {
isc_nmhandle_detach(&HANDLE_RECTYPE_NORMAL(client));
recursionquotatype_detach(client);
LOCK(&client->manager->reclock);
if (ISC_LINK_LINKED(client, rlink)) {
ISC_LIST_UNLINK(client->manager->recursing, client, rlink);
}
UNLOCK(&client->manager->reclock);
ns_client_putrdataset(client, &rdataset);
if (sigrdataset != NULL) {
ns_client_putrdataset(client, &sigrdataset);
}
recursionquotatype_detach(client);
isc_nmhandle_detach(&HANDLE_RECTYPE_NORMAL(client));
}
/*
@@ -6610,6 +6618,12 @@ ns_query_hookasync(query_ctx_t *qctx, ns_query_starthookasync_t runasync,
cleanup_and_detach_from_quota:
recursionquotatype_detach(client);
LOCK(&client->manager->reclock);
if (ISC_LINK_LINKED(client, rlink)) {
ISC_LIST_UNLINK(client->manager->recursing, client, rlink);
}
UNLOCK(&client->manager->reclock);
cleanup:
/*
* If we fail, send SERVFAIL now. It may be better to let the caller