]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make authdb version lookup return isc_result_t
authorAlessio Podda <alessio@isc.org>
Thu, 9 Jul 2026 11:58:10 +0000 (13:58 +0200)
committerAlessio Podda <alessio@isc.org>
Fri, 17 Jul 2026 11:48:46 +0000 (11:48 +0000)
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.

lib/ns/client.c
lib/ns/include/ns/client.h
lib/ns/query.c

index 4c5a701db7d7a78243f2877a66c669b9fd9ce6bd..1025d3dbe21c9840a4fb349e7775721a741ba15a 100644 (file)
@@ -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;
index c0bb2533b6efda81b2d4b0bf5d3497e31c9b8e4d..d0608a38aa17dbf356461a177391b981d8929289 100644 (file)
@@ -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);
index a695ff5ca6fab40c458869d9ba8e84d771b803dc..edb0e770e0bc4f84d578fcedd394ea8ab33a9e8c 100644 (file)
@@ -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;