From: Alessio Podda Date: Thu, 9 Jul 2026 11:58:10 +0000 (+0200) Subject: Make authdb version lookup return isc_result_t X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b15703343e8185b44b2f8c82db65361f2986b34b;p=thirdparty%2Fbind9.git Make authdb version lookup return isc_result_t Returning isc_result_t is more idiomatic. Also, there was some shared code between ns_client_findversionid and ns_client_findversion that has now been extracted into an helper function. --- diff --git a/lib/ns/client.c b/lib/ns/client.c index 4c5a701db7d..1025d3dbe21 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -3166,8 +3166,8 @@ client_getdbversion(ns_client_t *client) { return dbversion; } -ns_dbversion_t * -ns_client_findversionid(ns_client_t *client, uintptr_t dbid) { +static ns_dbversion_t * +client_findversionid(ns_client_t *client, uintptr_t dbid) { ISC_LIST_FOREACH(client->query.activeversions, dbversion, link) { if ((uintptr_t)dbversion->db == dbid) { return dbversion; @@ -3177,19 +3177,34 @@ ns_client_findversionid(ns_client_t *client, uintptr_t dbid) { return NULL; } +isc_result_t +ns_client_findversionid(ns_client_t *client, uintptr_t dbid, + ns_dbversion_t **dbversionp) { + ns_dbversion_t *dbversion = NULL; + + REQUIRE(dbversionp != NULL && *dbversionp == NULL); + + dbversion = client_findversionid(client, dbid); + if (dbversion == NULL) { + return ISC_R_NOTFOUND; + } + + *dbversionp = dbversion; + return ISC_R_SUCCESS; +} + ns_dbversion_t * ns_client_findversion(ns_client_t *client, dns_db_t *db) { - ISC_LIST_FOREACH(client->query.activeversions, dbversion, link) { - if (dbversion->db == db) { - return dbversion; - } + ns_dbversion_t *dbversion = client_findversionid(client, (uintptr_t)db); + if (dbversion != NULL) { + return dbversion; } /* * This is a new zone for this query. Add it to * the active list. */ - ns_dbversion_t *dbversion = client_getdbversion(client); + dbversion = client_getdbversion(client); dns_db_attach(db, &dbversion->db); dns_db_currentversion(db, &dbversion->version); dbversion->acl_checked = false; diff --git a/lib/ns/include/ns/client.h b/lib/ns/include/ns/client.h index c0bb2533b6e..d0608a38aa1 100644 --- a/lib/ns/include/ns/client.h +++ b/lib/ns/include/ns/client.h @@ -563,11 +563,21 @@ ns_client_findversion(ns_client_t *client, dns_db_t *db); * allocated by ns_client_newdbversion(). */ -ns_dbversion_t * -ns_client_findversionid(ns_client_t *client, uintptr_t dbid); +isc_result_t +ns_client_findversionid(ns_client_t *client, uintptr_t dbid, + ns_dbversion_t **dbversionp); /*%< * Find the active database version matching database identity 'dbid', * without allocating a new database version if none is found. + * + * Requires: + * + *\li 'dbversionp' points to a NULL ns_dbversion_t *. + * + * Returns: + * + *\li #ISC_R_SUCCESS A matching database version was found. + *\li #ISC_R_NOTFOUND No matching database version was found. */ ISC_REFCOUNT_DECL(ns_clientmgr); diff --git a/lib/ns/query.c b/lib/ns/query.c index a695ff5ca6f..edb0e770e0b 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -1659,10 +1659,8 @@ query_additionalauth(query_ctx_t *qctx, const dns_name_t *name, * First, look within the same zone database for authoritative * additional data. */ - dbversion = ns_client_findversionid(client, client->query.authdb_id); - if (dbversion == NULL) { - return ISC_R_NOTFOUND; - } + RETERR(ns_client_findversionid(client, client->query.authdb_id, + &dbversion)); dns_db_attach(dbversion->db, &db); version = dbversion->version;