2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 15:05:23 +00:00

Lock dispatch when canceling connect

When canceling pending connections, the disp->pending list
was accessed unlocked.
This commit is contained in:
Ondřej Surý
2021-10-18 11:49:56 +02:00
committed by Evan Hunt
parent f0931c07e7
commit a0bb05faf6

View File

@@ -1483,6 +1483,7 @@ dns_dispatch_getnext(dns_dispentry_t *resp) {
void void
dns_dispatch_cancel(dns_dispentry_t **respp) { dns_dispatch_cancel(dns_dispentry_t **respp) {
dns_dispentry_t *resp = NULL; dns_dispentry_t *resp = NULL;
dns_dispatch_t *disp = NULL;
REQUIRE(respp != NULL); REQUIRE(respp != NULL);
@@ -1491,6 +1492,7 @@ dns_dispatch_cancel(dns_dispentry_t **respp) {
REQUIRE(VALID_RESPONSE(resp)); REQUIRE(VALID_RESPONSE(resp));
disp = resp->disp;
resp->canceled = true; resp->canceled = true;
/* Connected UDP. */ /* Connected UDP. */
@@ -1499,11 +1501,12 @@ dns_dispatch_cancel(dns_dispentry_t **respp) {
goto done; goto done;
} }
LOCK(&disp->lock);
/* TCP pending connection. */ /* TCP pending connection. */
if (ISC_LINK_LINKED(resp, plink)) { if (ISC_LINK_LINKED(resp, plink)) {
dns_dispentry_t *copy = resp; dns_dispentry_t *copy = resp;
ISC_LIST_UNLINK(resp->disp->pending, resp, plink); ISC_LIST_UNLINK(disp->pending, resp, plink);
if (resp->connected != NULL) { if (resp->connected != NULL) {
resp->connected(ISC_R_CANCELED, NULL, resp->arg); resp->connected(ISC_R_CANCELED, NULL, resp->arg);
} }
@@ -1516,6 +1519,7 @@ dns_dispatch_cancel(dns_dispentry_t **respp) {
* dns_dispatch_done(). * dns_dispatch_done().
*/ */
dispentry_detach(&copy); dispentry_detach(&copy);
UNLOCK(&disp->lock);
goto done; goto done;
} }
@@ -1526,14 +1530,14 @@ dns_dispatch_cancel(dns_dispentry_t **respp) {
* unless this is the last resp waiting. * unless this is the last resp waiting.
*/ */
if (ISC_LINK_LINKED(resp, alink)) { if (ISC_LINK_LINKED(resp, alink)) {
ISC_LIST_UNLINK(resp->disp->active, resp, alink); ISC_LIST_UNLINK(disp->active, resp, alink);
if (ISC_LIST_EMPTY(resp->disp->active) && if (ISC_LIST_EMPTY(disp->active) && disp->handle != NULL) {
resp->disp->handle != NULL) { isc_nm_cancelread(disp->handle);
isc_nm_cancelread(resp->disp->handle);
} else if (resp->response != NULL) { } else if (resp->response != NULL) {
resp->response(ISC_R_CANCELED, NULL, resp->arg); resp->response(ISC_R_CANCELED, NULL, resp->arg);
} }
} }
UNLOCK(&disp->lock);
done: done:
dns_dispatch_done(&resp); dns_dispatch_done(&resp);