2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 10:10:06 +00:00

Remove ns_query_init() cannot fail, remove the error paths

As ns_query_init() cannot fail now, remove the error paths, especially
in ns__client_setup() where we now don't have to care what to do with
the connection if setting up the client could fail.  It couldn't fail
even before, but now it's formal.
This commit is contained in:
Ondřej Surý 2024-07-02 20:17:49 +02:00
parent bc3e713317
commit 1c0564d715
No known key found for this signature in database
GPG Key ID: 2820F37E873DEA41
7 changed files with 12 additions and 42 deletions

View File

@ -1838,19 +1838,13 @@ ns_client_request(isc_nmhandle_t *handle, isc_result_t eresult,
client = isc_mem_get(clientmgr->mctx, sizeof(*client));
result = ns__client_setup(client, clientmgr, true);
if (result != ISC_R_SUCCESS) {
return;
}
ns__client_setup(client, clientmgr, true);
ns_client_log(client, DNS_LOGCATEGORY_SECURITY,
NS_LOGMODULE_CLIENT, ISC_LOG_DEBUG(3),
"allocate new client");
} else {
result = ns__client_setup(client, NULL, false);
if (result != ISC_R_SUCCESS) {
return;
}
ns__client_setup(client, NULL, false);
}
client->state = NS_CLIENTSTATE_READY;
@ -2520,10 +2514,8 @@ ns__client_tcpconn(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
return (ISC_R_SUCCESS);
}
isc_result_t
void
ns__client_setup(ns_client_t *client, ns_clientmgr_t *mgr, bool new) {
isc_result_t result;
/*
* Note: creating a client does not add the client to the
* manager's client list, the caller is responsible for that.
@ -2548,10 +2540,7 @@ ns__client_setup(ns_client_t *client, ns_clientmgr_t *mgr, bool new) {
* and the functions it calls will require it.
*/
client->magic = NS_CLIENT_MAGIC;
result = ns_query_init(client);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
ns_query_init(client);
} else {
REQUIRE(NS_CLIENT_VALID(client));
REQUIRE(client->manager->tid == isc_tid());
@ -2583,14 +2572,6 @@ ns__client_setup(ns_client_t *client, ns_clientmgr_t *mgr, bool new) {
client->magic = NS_CLIENT_MAGIC;
CTRACE("client_setup");
return (ISC_R_SUCCESS);
cleanup:
dns_message_detach(&client->message);
ns_clientmgr_detach(&client->manager);
return (result);
}
/***

View File

@ -543,7 +543,7 @@ ns_client_findversion(ns_client_t *client, dns_db_t *db);
ISC_REFCOUNT_DECL(ns_clientmgr);
isc_result_t
void
ns__client_setup(ns_client_t *client, ns_clientmgr_t *manager, bool new);
/*%<
* Perform initial setup of an allocated client.

View File

@ -287,7 +287,7 @@ ns_query_hookasync(query_ctx_t *qctx, ns_query_starthookasync_t runasync,
* other aspects of hook-triggered asynchronous event handling.
*/
isc_result_t
void
ns_query_init(ns_client_t *client);
void

View File

@ -806,10 +806,8 @@ ns_query_free(ns_client_t *client) {
query_reset(client, true);
}
isc_result_t
void
ns_query_init(ns_client_t *client) {
isc_result_t result = ISC_R_SUCCESS;
REQUIRE(NS_CLIENT_VALID(client));
client->query = (ns_query_t){ 0 };
@ -827,8 +825,6 @@ ns_query_init(ns_client_t *client) {
query_reset(client, false);
ns_client_newdbversion(client, 3);
ns_client_newnamebuf(client);
return (result);
}
/*%

View File

@ -88,7 +88,7 @@ isc_result_t
ns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz,
size_t *sizep);
isc_result_t
void
ns_test_getclient(ns_interface_t *ifp0, bool tcp, ns_client_t **clientp);
/*%

View File

@ -216,9 +216,8 @@ ns_test_cleanup_zone(void) {
dns_zone_detach(&served_zone);
}
isc_result_t
void
ns_test_getclient(ns_interface_t *ifp0, bool tcp, ns_client_t **clientp) {
isc_result_t result;
ns_client_t *client;
ns_clientmgr_t *clientmgr;
int i;
@ -229,7 +228,7 @@ ns_test_getclient(ns_interface_t *ifp0, bool tcp, ns_client_t **clientp) {
clientmgr = ns_interfacemgr_getclientmgr(interfacemgr);
client = isc_mem_get(clientmgr->mctx, sizeof(*client));
result = ns__client_setup(client, clientmgr, true);
ns__client_setup(client, clientmgr, true);
for (i = 0; i < 32; i++) {
if (atomic_load(&client_addrs[i]) == (uintptr_t)NULL ||
@ -244,8 +243,6 @@ ns_test_getclient(ns_interface_t *ifp0, bool tcp, ns_client_t **clientp) {
atomic_store(&client_addrs[i], (uintptr_t)client);
client->handle = (isc_nmhandle_t *)client; /* Hack */
*clientp = client;
return (result);
}
/*%
@ -438,10 +435,7 @@ ns_test_qctx_create(const ns_test_qctx_create_params_t *params,
/*
* Allocate and initialize a client structure.
*/
result = ns_test_getclient(NULL, false, &client);
if (result != ISC_R_SUCCESS) {
return (result);
}
ns_test_getclient(NULL, false, &client);
client->tnow = isc_time_now();
/*

View File

@ -67,8 +67,7 @@ ISC_LOOP_TEST_IMPL(notify_start) {
isc_buffer_t nbuf;
size_t nsize;
result = ns_test_getclient(NULL, false, &client);
assert_int_equal(result, ISC_R_SUCCESS);
ns_test_getclient(NULL, false, &client);
result = dns_test_makeview("view", false, false, &client->view);
assert_int_equal(result, ISC_R_SUCCESS);