Blame SOURCES/bind-9.11.4-missing-DBC-checks.patch

ee1d55
From c0a3c488020120b82acc03cf68d347722b38123a Mon Sep 17 00:00:00 2001
ee1d55
From: Mark Andrews <marka@isc.org>
ee1d55
Date: Wed, 28 Nov 2018 18:57:38 +1100
ee1d55
Subject: [PATCH] add missing DBC checks for catz and add isc_magic checks; add
ee1d55
 DBC checks to ht.c
ee1d55
ee1d55
5103.  [bug]           Add missing design by contract tests to dns_catz*.
ee1d55
                       [GL #748]
ee1d55
ee1d55
(cherry picked from commit a487473fc554baf1421193c6803dad466f470af5)
ee1d55
(cherry picked from commit 17d9fa3cc70b29c8dcf4495170bfc3f6c79f9083)
ee1d55
(cherry picked from commit c0a3c488020120b82acc03cf68d347722b38123a)
ee1d55
---
ee1d55
 lib/dns/catz.c             | 135 ++++++++++++++++++++++-----------
ee1d55
 lib/dns/include/dns/catz.h | 148 +++++++++++++++++++------------------
ee1d55
 lib/isc/ht.c               |   6 +-
ee1d55
 lib/isc/include/isc/ht.h   |  37 ++++++++--
ee1d55
 lib/isc/tests/ht_test.c    |  11 ++-
ee1d55
 5 files changed, 215 insertions(+), 122 deletions(-)
ee1d55
ee1d55
diff --git a/lib/dns/catz.c b/lib/dns/catz.c
ee1d55
index 7218430..767c710 100644
ee1d55
--- a/lib/dns/catz.c
ee1d55
+++ b/lib/dns/catz.c
ee1d55
@@ -29,11 +29,19 @@
ee1d55
 #include <dns/view.h>
ee1d55
 #include <dns/zone.h>
ee1d55
 
ee1d55
+#define DNS_CATZ_ZONE_MAGIC ISC_MAGIC('c', 'a', 't', 'z')
ee1d55
+#define DNS_CATZ_ZONES_MAGIC ISC_MAGIC('c', 'a', 't', 's')
ee1d55
+#define DNS_CATZ_ENTRY_MAGIC ISC_MAGIC('c', 'a', 't', 'e')
ee1d55
+
ee1d55
+#define DNS_CATZ_ZONE_VALID(catz) ISC_MAGIC_VALID(catz, DNS_CATZ_ZONE_MAGIC)
ee1d55
+#define DNS_CATZ_ZONES_VALID(catzs) ISC_MAGIC_VALID(catzs, DNS_CATZ_ZONES_MAGIC)
ee1d55
+#define DNS_CATZ_ENTRY_VALID(entry) ISC_MAGIC_VALID(entry, DNS_CATZ_ENTRY_MAGIC)
ee1d55
 
ee1d55
 /*%
ee1d55
  * Single member zone in a catalog
ee1d55
  */
ee1d55
 struct dns_catz_entry {
ee1d55
+	unsigned int		magic;
ee1d55
 	dns_name_t		name;
ee1d55
 	dns_catz_options_t	opts;
ee1d55
 	isc_refcount_t		refs;
ee1d55
@@ -43,6 +51,7 @@ struct dns_catz_entry {
ee1d55
  * Catalog zone
ee1d55
  */
ee1d55
 struct dns_catz_zone {
ee1d55
+	unsigned int		magic;
ee1d55
 	dns_name_t		name;
ee1d55
 	dns_catz_zones_t	*catzs;
ee1d55
 	dns_rdata_t		soa;
ee1d55
@@ -81,6 +90,7 @@ catz_process_zones_suboption(dns_catz_zone_t *zone, dns_rdataset_t *value,
ee1d55
  * Collection of catalog zones for a view
ee1d55
  */
ee1d55
 struct dns_catz_zones {
ee1d55
+	unsigned int			magic;
ee1d55
 	isc_ht_t			*zones;
ee1d55
 	isc_mem_t			*mctx;
ee1d55
 	isc_refcount_t			refs;
ee1d55
@@ -94,6 +104,9 @@ struct dns_catz_zones {
ee1d55
 
ee1d55
 void
ee1d55
 dns_catz_options_init(dns_catz_options_t *options) {
ee1d55
+
ee1d55
+	REQUIRE(options != NULL);
ee1d55
+
ee1d55
 	dns_ipkeylist_init(&options->masters);
ee1d55
 
ee1d55
 	options->allow_query = NULL;
ee1d55
@@ -109,6 +122,10 @@ dns_catz_options_init(dns_catz_options_t *options) {
ee1d55
 
ee1d55
 void
ee1d55
 dns_catz_options_free(dns_catz_options_t *options, isc_mem_t *mctx) {
ee1d55
+
ee1d55
+	REQUIRE(options != NULL);
ee1d55
+	REQUIRE(mctx != NULL);
ee1d55
+
ee1d55
 	if (options->masters.count != 0)
ee1d55
 		dns_ipkeylist_clear(mctx, &options->masters);
ee1d55
 	if (options->zonedir != NULL) {
ee1d55
@@ -125,6 +142,7 @@ isc_result_t
ee1d55
 dns_catz_options_copy(isc_mem_t *mctx, const dns_catz_options_t *src,
ee1d55
 		      dns_catz_options_t *dst)
ee1d55
 {
ee1d55
+	REQUIRE(mctx != NULL);
ee1d55
 	REQUIRE(src != NULL);
ee1d55
 	REQUIRE(dst != NULL);
ee1d55
 	REQUIRE(dst->masters.count == 0);
ee1d55
@@ -155,6 +173,10 @@ isc_result_t
ee1d55
 dns_catz_options_setdefault(isc_mem_t *mctx, const dns_catz_options_t *defaults,
ee1d55
 			    dns_catz_options_t *opts)
ee1d55
 {
ee1d55
+	REQUIRE(mctx != NULL);
ee1d55
+	REQUIRE(defaults != NULL);
ee1d55
+	REQUIRE(opts != NULL);
ee1d55
+
ee1d55
 	if (opts->masters.count == 0 && defaults->masters.count != 0)
ee1d55
 		dns_ipkeylist_copy(mctx, &defaults->masters, &opts->masters);
ee1d55
 
ee1d55
@@ -179,6 +201,7 @@ dns_catz_entry_new(isc_mem_t *mctx, const dns_name_t *domain,
ee1d55
 	dns_catz_entry_t *nentry;
ee1d55
 	isc_result_t result;
ee1d55
 
ee1d55
+	REQUIRE(mctx != NULL);
ee1d55
 	REQUIRE(nentryp != NULL && *nentryp == NULL);
ee1d55
 
ee1d55
 	nentry = isc_mem_get(mctx, sizeof(dns_catz_entry_t));
ee1d55
@@ -194,6 +217,7 @@ dns_catz_entry_new(isc_mem_t *mctx, const dns_name_t *domain,
ee1d55
 
ee1d55
 	dns_catz_options_init(&nentry->opts);
ee1d55
 	isc_refcount_init(&nentry->refs, 1);
ee1d55
+	nentry->magic = DNS_CATZ_ENTRY_MAGIC;
ee1d55
 	*nentryp = nentry;
ee1d55
 	return (ISC_R_SUCCESS);
ee1d55
 
ee1d55
@@ -204,6 +228,7 @@ cleanup:
ee1d55
 
ee1d55
 dns_name_t *
ee1d55
 dns_catz_entry_getname(dns_catz_entry_t *entry) {
ee1d55
+	REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
ee1d55
 	return (&entry->name);
ee1d55
 }
ee1d55
 
ee1d55
@@ -214,6 +239,10 @@ dns_catz_entry_copy(dns_catz_zone_t *zone, const dns_catz_entry_t *entry,
ee1d55
 	isc_result_t result;
ee1d55
 	dns_catz_entry_t *nentry = NULL;
ee1d55
 
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
+	REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
ee1d55
+	REQUIRE(nentryp != NULL && *nentryp == NULL);
ee1d55
+
ee1d55
 	result = dns_catz_entry_new(zone->catzs->mctx, &entry->name, &nentry);
ee1d55
 	if (result != ISC_R_SUCCESS)
ee1d55
 		return (result);
ee1d55
@@ -229,7 +258,9 @@ dns_catz_entry_copy(dns_catz_zone_t *zone, const dns_catz_entry_t *entry,
ee1d55
 
ee1d55
 void
ee1d55
 dns_catz_entry_attach(dns_catz_entry_t *entry, dns_catz_entry_t **entryp) {
ee1d55
+	REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
ee1d55
 	REQUIRE(entryp != NULL && *entryp == NULL);
ee1d55
+
ee1d55
 	isc_refcount_increment(&entry->refs, NULL);
ee1d55
 	*entryp = entry;
ee1d55
 }
ee1d55
@@ -240,9 +271,11 @@ dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp) {
ee1d55
 	isc_mem_t *mctx;
ee1d55
 	unsigned int refs;
ee1d55
 
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
 	REQUIRE(entryp != NULL && *entryp != NULL);
ee1d55
-
ee1d55
 	entry = *entryp;
ee1d55
+	REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
ee1d55
+
ee1d55
 	*entryp = NULL;
ee1d55
 
ee1d55
 	mctx = zone->catzs->mctx;
ee1d55
@@ -259,6 +292,7 @@ dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp) {
ee1d55
 
ee1d55
 isc_boolean_t
ee1d55
 dns_catz_entry_validate(const dns_catz_entry_t *entry) {
ee1d55
+	REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
ee1d55
 	UNUSED(entry);
ee1d55
 
ee1d55
 	return (ISC_TRUE);
ee1d55
@@ -268,6 +302,9 @@ isc_boolean_t
ee1d55
 dns_catz_entry_cmp(const dns_catz_entry_t *ea, const dns_catz_entry_t *eb) {
ee1d55
 	isc_region_t ra, rb;
ee1d55
 
ee1d55
+	REQUIRE(DNS_CATZ_ENTRY_VALID(ea));
ee1d55
+	REQUIRE(DNS_CATZ_ENTRY_VALID(eb));
ee1d55
+
ee1d55
 	if (ea == eb)
ee1d55
 		return (ISC_TRUE);
ee1d55
 
ee1d55
@@ -308,21 +345,21 @@ dns_catz_entry_cmp(const dns_catz_entry_t *ea, const dns_catz_entry_t *eb) {
ee1d55
 
ee1d55
 dns_name_t *
ee1d55
 dns_catz_zone_getname(dns_catz_zone_t *zone) {
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
 
ee1d55
 	return (&zone->name);
ee1d55
 }
ee1d55
 
ee1d55
 dns_catz_options_t *
ee1d55
 dns_catz_zone_getdefoptions(dns_catz_zone_t *zone) {
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
 
ee1d55
 	return (&zone->defoptions);
ee1d55
 }
ee1d55
 
ee1d55
 void
ee1d55
 dns_catz_zone_resetdefoptions(dns_catz_zone_t *zone) {
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
 
ee1d55
 	dns_catz_options_free(&zone->defoptions, zone->catzs->mctx);
ee1d55
 	dns_catz_options_init(&zone->defoptions);
ee1d55
@@ -339,8 +376,8 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) {
ee1d55
 	char zname[DNS_NAME_FORMATSIZE];
ee1d55
 	dns_catz_zoneop_fn_t addzone, modzone, delzone;
ee1d55
 
ee1d55
-	REQUIRE(target != NULL);
ee1d55
-	REQUIRE(newzone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(newzone));
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(target));
ee1d55
 
ee1d55
 	/* TODO verify the new zone first! */
ee1d55
 
ee1d55
@@ -395,9 +432,9 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) {
ee1d55
 	     result = delcur ? isc_ht_iter_delcurrent_next(iter1) :
ee1d55
 			     isc_ht_iter_next(iter1))
ee1d55
 	{
ee1d55
-		dns_catz_entry_t *nentry;
ee1d55
-		dns_catz_entry_t *oentry;
ee1d55
-		unsigned char * key;
ee1d55
+		dns_catz_entry_t *nentry = NULL;
ee1d55
+		dns_catz_entry_t *oentry = NULL;
ee1d55
+		unsigned char * key = NULL;
ee1d55
 		size_t keysize;
ee1d55
 		delcur = ISC_FALSE;
ee1d55
 
ee1d55
@@ -468,7 +505,7 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) {
ee1d55
 	     result == ISC_R_SUCCESS;
ee1d55
 	     result = isc_ht_iter_delcurrent_next(iter2))
ee1d55
 	{
ee1d55
-		dns_catz_entry_t *entry;
ee1d55
+		dns_catz_entry_t *entry = NULL;
ee1d55
 		isc_ht_iter_current(iter2, (void **) &entry);
ee1d55
 
ee1d55
 		dns_name_format(&entry->name, zname, DNS_NAME_FORMATSIZE);
ee1d55
@@ -491,7 +528,7 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) {
ee1d55
 	     result == ISC_R_SUCCESS;
ee1d55
 	     result = isc_ht_iter_delcurrent_next(iteradd))
ee1d55
 	{
ee1d55
-		dns_catz_entry_t *entry;
ee1d55
+		dns_catz_entry_t *entry = NULL;
ee1d55
 		isc_ht_iter_current(iteradd, (void **) &entry);
ee1d55
 
ee1d55
 		dns_name_format(&entry->name, zname, DNS_NAME_FORMATSIZE);
ee1d55
@@ -510,7 +547,7 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) {
ee1d55
 	     result == ISC_R_SUCCESS;
ee1d55
 	     result = isc_ht_iter_delcurrent_next(itermod))
ee1d55
 	{
ee1d55
-		dns_catz_entry_t *entry;
ee1d55
+		dns_catz_entry_t *entry = NULL;
ee1d55
 		isc_ht_iter_current(itermod, (void **) &entry);
ee1d55
 		result = modzone(entry, target, target->catzs->view,
ee1d55
 				 target->catzs->taskmgr,
ee1d55
@@ -542,7 +579,6 @@ cleanup:
ee1d55
 	if (tomod != NULL)
ee1d55
 		isc_ht_destroy(&tomod);
ee1d55
 	return (result);
ee1d55
-
ee1d55
 }
ee1d55
 
ee1d55
 isc_result_t
ee1d55
@@ -581,6 +617,7 @@ dns_catz_new_zones(dns_catz_zones_t **catzsp, dns_catz_zonemodmethods_t *zmm,
ee1d55
 	result = isc_task_create(taskmgr, 0, &new_zones->updater);
ee1d55
 	if (result != ISC_R_SUCCESS)
ee1d55
 		goto cleanup_ht;
ee1d55
+	new_zones->magic = DNS_CATZ_ZONES_MAGIC;
ee1d55
 
ee1d55
 	*catzsp = new_zones;
ee1d55
 	return (ISC_R_SUCCESS);
ee1d55
@@ -599,7 +636,7 @@ dns_catz_new_zones(dns_catz_zones_t **catzsp, dns_catz_zonemodmethods_t *zmm,
ee1d55
 
ee1d55
 void
ee1d55
 dns_catz_catzs_set_view(dns_catz_zones_t *catzs, dns_view_t *view) {
ee1d55
-	REQUIRE(catzs != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
ee1d55
 	REQUIRE(view != NULL);
ee1d55
 	/* Either it's a new one or it's being reconfigured. */
ee1d55
 	REQUIRE(catzs->view == NULL || !strcmp(catzs->view->name, view->name));
ee1d55
@@ -614,7 +651,9 @@ dns_catz_new_zone(dns_catz_zones_t *catzs, dns_catz_zone_t **zonep,
ee1d55
 	isc_result_t result;
ee1d55
 	dns_catz_zone_t *new_zone;
ee1d55
 
ee1d55
+	REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
ee1d55
 	REQUIRE(zonep != NULL && *zonep == NULL);
ee1d55
+	REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
ee1d55
 
ee1d55
 	new_zone = isc_mem_get(catzs->mctx, sizeof(*new_zone));
ee1d55
 	if (new_zone == NULL)
ee1d55
@@ -651,6 +690,7 @@ dns_catz_new_zone(dns_catz_zones_t *catzs, dns_catz_zone_t **zonep,
ee1d55
 	new_zone->db_registered = ISC_FALSE;
ee1d55
 	new_zone->version = (isc_uint32_t)(-1);
ee1d55
 	isc_refcount_init(&new_zone->refs, 1);
ee1d55
+	new_zone->magic = DNS_CATZ_ZONE_MAGIC;
ee1d55
 
ee1d55
 	*zonep = new_zone;
ee1d55
 
ee1d55
@@ -674,9 +714,10 @@ dns_catz_add_zone(dns_catz_zones_t *catzs, const dns_name_t *name,
ee1d55
 	isc_result_t result, tresult;
ee1d55
 	char zname[DNS_NAME_FORMATSIZE];
ee1d55
 
ee1d55
-	REQUIRE(catzs != NULL);
ee1d55
-	REQUIRE(name != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
ee1d55
+	REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
ee1d55
 	REQUIRE(zonep != NULL && *zonep == NULL);
ee1d55
+
ee1d55
 	dns_name_format(name, zname, DNS_NAME_FORMATSIZE);
ee1d55
 	isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
ee1d55
 		      DNS_LOGMODULE_MASTER, ISC_LOG_DEBUG(3),
ee1d55
@@ -714,7 +755,10 @@ dns_catz_add_zone(dns_catz_zones_t *catzs, const dns_name_t *name,
ee1d55
 dns_catz_zone_t *
ee1d55
 dns_catz_get_zone(dns_catz_zones_t *catzs, const dns_name_t *name) {
ee1d55
 	isc_result_t result;
ee1d55
-	dns_catz_zone_t *found;
ee1d55
+	dns_catz_zone_t *found = NULL;
ee1d55
+
ee1d55
+	REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
ee1d55
+	REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
ee1d55
 
ee1d55
 	result = isc_ht_find(catzs->zones, name->ndata, name->length,
ee1d55
 			     (void **) &found);
ee1d55
@@ -726,6 +770,7 @@ dns_catz_get_zone(dns_catz_zones_t *catzs, const dns_name_t *name) {
ee1d55
 
ee1d55
 void
ee1d55
 dns_catz_catzs_attach(dns_catz_zones_t *catzs, dns_catz_zones_t **catzsp) {
ee1d55
+	REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
ee1d55
 	REQUIRE(catzsp != NULL && *catzsp == NULL);
ee1d55
 
ee1d55
 	isc_refcount_increment(&catzs->refs, NULL);
ee1d55
@@ -745,7 +790,6 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
ee1d55
 	isc_result_t result;
ee1d55
 	dns_catz_zone_t *zone;
ee1d55
 	isc_ht_iter_t *iter = NULL;
ee1d55
-	isc_mem_t *mctx;
ee1d55
 	unsigned int refs;
ee1d55
 
ee1d55
 	REQUIRE(zonep != NULL && *zonep != NULL);
ee1d55
@@ -754,6 +798,7 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
ee1d55
 	*zonep = NULL;
ee1d55
 	isc_refcount_decrement(&zone->refs, &refs);
ee1d55
 	if (refs == 0) {
ee1d55
+		isc_mem_t *mctx = zone->catzs->mctx;
ee1d55
 		if (zone->entries != NULL) {
ee1d55
 			result = isc_ht_iter_create(zone->entries, &iter);
ee1d55
 			INSIST(result == ISC_R_SUCCESS);
ee1d55
@@ -761,7 +806,7 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
ee1d55
 			     result == ISC_R_SUCCESS;
ee1d55
 			     result = isc_ht_iter_delcurrent_next(iter))
ee1d55
 			{
ee1d55
-				dns_catz_entry_t *entry;
ee1d55
+				dns_catz_entry_t *entry = NULL;
ee1d55
 
ee1d55
 				isc_ht_iter_current(iter, (void **) &entry);
ee1d55
 				dns_catz_entry_detach(zone, &entry);
ee1d55
@@ -773,7 +818,7 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
ee1d55
 			INSIST(isc_ht_count(zone->entries) == 0);
ee1d55
 			isc_ht_destroy(&zone->entries);
ee1d55
 		}
ee1d55
-		mctx = zone->catzs->mctx;
ee1d55
+		zone->magic = 0;
ee1d55
 		isc_timer_detach(&zone->updatetimer);
ee1d55
 		isc_refcount_destroy(&zone->refs);
ee1d55
 		if (zone->db_registered == ISC_TRUE) {
ee1d55
@@ -798,22 +843,21 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
ee1d55
 }
ee1d55
 
ee1d55
 void
ee1d55
-dns_catz_catzs_detach(dns_catz_zones_t ** catzsp) {
ee1d55
+dns_catz_catzs_detach(dns_catz_zones_t **catzsp) {
ee1d55
 	dns_catz_zones_t *catzs;
ee1d55
 	isc_ht_iter_t *iter = NULL;
ee1d55
 	isc_result_t result;
ee1d55
 	unsigned int refs;
ee1d55
-	dns_catz_zone_t *zone;
ee1d55
-
ee1d55
 
ee1d55
 	REQUIRE(catzsp != NULL);
ee1d55
 	catzs = *catzsp;
ee1d55
-	REQUIRE(catzs != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
ee1d55
 
ee1d55
 	*catzsp = NULL;
ee1d55
 	isc_refcount_decrement(&catzs->refs, &refs);
ee1d55
 
ee1d55
 	if (refs == 0) {
ee1d55
+		catzs->magic = 0;
ee1d55
 		DESTROYLOCK(&catzs->lock);
ee1d55
 		if (catzs->zones != NULL) {
ee1d55
 			result = isc_ht_iter_create(catzs->zones, &iter);
ee1d55
@@ -821,6 +865,7 @@ dns_catz_catzs_detach(dns_catz_zones_t ** catzsp) {
ee1d55
 			for (result = isc_ht_iter_first(iter);
ee1d55
 			     result == ISC_R_SUCCESS;)
ee1d55
 			{
ee1d55
+				dns_catz_zone_t *zone = NULL;
ee1d55
 				isc_ht_iter_current(iter, (void **) &zone);
ee1d55
 				result = isc_ht_iter_delcurrent_next(iter);
ee1d55
 				dns_catz_zone_detach(&zone);
ee1d55
@@ -878,9 +923,9 @@ catz_process_zones(dns_catz_zone_t *zone, dns_rdataset_t *value,
ee1d55
 	dns_label_t mhash;
ee1d55
 	dns_name_t opt;
ee1d55
 
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
 	REQUIRE(DNS_RDATASET_VALID(value));
ee1d55
-	REQUIRE(name != NULL);
ee1d55
+	REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
ee1d55
 
ee1d55
 	if (value->rdclass != dns_rdataclass_in)
ee1d55
 		return (ISC_R_FAILURE);
ee1d55
@@ -971,7 +1016,7 @@ catz_process_version(dns_catz_zone_t *zone, dns_rdataset_t *value) {
ee1d55
 	isc_uint32_t tversion;
ee1d55
 	char t[16];
ee1d55
 
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
 	REQUIRE(DNS_RDATASET_VALID(value));
ee1d55
 
ee1d55
 	if (value->rdclass != dns_rdataclass_in ||
ee1d55
@@ -1036,11 +1081,11 @@ catz_process_masters(dns_catz_zone_t *zone, dns_ipkeylist_t *ipkl,
ee1d55
 	unsigned int rcount;
ee1d55
 	unsigned int i;
ee1d55
 
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
 	REQUIRE(ipkl != NULL);
ee1d55
 	REQUIRE(DNS_RDATASET_VALID(value));
ee1d55
 	REQUIRE(dns_rdataset_isassociated(value));
ee1d55
-	REQUIRE(name != NULL);
ee1d55
+	REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
ee1d55
 
ee1d55
 	mctx = zone->catzs->mctx;
ee1d55
 	memset(&rdata_a, 0, sizeof(rdata_a));
ee1d55
@@ -1220,7 +1265,7 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp,
ee1d55
 	isc_buffer_t *aclb = NULL;
ee1d55
 	unsigned char buf[256]; /* larger than INET6_ADDRSTRLEN */
ee1d55
 
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
 	REQUIRE(aclbp != NULL);
ee1d55
 	REQUIRE(*aclbp == NULL);
ee1d55
 	REQUIRE(DNS_RDATASET_VALID(value));
ee1d55
@@ -1297,9 +1342,10 @@ catz_process_zones_suboption(dns_catz_zone_t *zone, dns_rdataset_t *value,
ee1d55
 	dns_name_t prefix;
ee1d55
 	catz_opt_t opt;
ee1d55
 
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
 	REQUIRE(mhash != NULL);
ee1d55
 	REQUIRE(DNS_RDATASET_VALID(value));
ee1d55
+	REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
ee1d55
 
ee1d55
 	if (name->labels == 0)
ee1d55
 		return (ISC_R_FAILURE);
ee1d55
@@ -1355,8 +1401,8 @@ catz_process_value(dns_catz_zone_t *zone, dns_name_t *name,
ee1d55
 	dns_name_t prefix;
ee1d55
 	catz_opt_t opt;
ee1d55
 
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
-	REQUIRE(name != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
+	REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
ee1d55
 	REQUIRE(DNS_RDATASET_VALID(rdataset));
ee1d55
 
ee1d55
 	dns_name_getlabel(name, name->labels - 1, &option);
ee1d55
@@ -1401,8 +1447,9 @@ dns_catz_update_process(dns_catz_zones_t *catzs, dns_catz_zone_t *zone,
ee1d55
 	dns_rdata_soa_t soa;
ee1d55
 	dns_name_t prefix;
ee1d55
 
ee1d55
-	REQUIRE(catzs != NULL);
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
+	REQUIRE(ISC_MAGIC_VALID(src_name, DNS_NAME_MAGIC));
ee1d55
 
ee1d55
 	nrres = dns_name_fullcompare(src_name, &zone->name, &order, &nlabels);
ee1d55
 	if (nrres == dns_namereln_equal) {
ee1d55
@@ -1446,7 +1493,7 @@ dns_catz_generate_masterfilename(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
ee1d55
 	isc_result_t result;
ee1d55
 	size_t rlen;
ee1d55
 
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
 	REQUIRE(entry != NULL);
ee1d55
 	REQUIRE(buffer != NULL && *buffer != NULL);
ee1d55
 
ee1d55
@@ -1523,7 +1570,7 @@ dns_catz_generate_zonecfg(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
ee1d55
 	char pbuf[sizeof("65535")]; /* used both for port number and DSCP */
ee1d55
 	char zname[DNS_NAME_FORMATSIZE];
ee1d55
 
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
 	REQUIRE(entry != NULL);
ee1d55
 	REQUIRE(buf != NULL && *buf == NULL);
ee1d55
 
ee1d55
@@ -1635,7 +1682,7 @@ dns_catz_update_taskaction(isc_task_t *task, isc_event_t *event) {
ee1d55
 
ee1d55
 	REQUIRE(event != NULL);
ee1d55
 	zone = event->ev_arg;
ee1d55
-	REQUIRE(zone != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(zone));
ee1d55
 
ee1d55
 	LOCK(&zone->catzs->lock);
ee1d55
 	zone->updatepending = ISC_FALSE;
ee1d55
@@ -1747,7 +1794,7 @@ dns_catz_update_from_db(dns_db_t *db, dns_catz_zones_t *catzs) {
ee1d55
 	isc_uint32_t vers;
ee1d55
 
ee1d55
 	REQUIRE(DNS_DB_VALID(db));
ee1d55
-	REQUIRE(catzs != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
ee1d55
 
ee1d55
 	/*
ee1d55
 	 * Create a new catz in the same context as current catz.
ee1d55
@@ -1920,9 +1967,8 @@ void
ee1d55
 dns_catz_prereconfig(dns_catz_zones_t *catzs) {
ee1d55
 	isc_result_t result;
ee1d55
 	isc_ht_iter_t *iter = NULL;
ee1d55
-	dns_catz_zone_t *zone;
ee1d55
 
ee1d55
-	REQUIRE(catzs != NULL);
ee1d55
+	REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
ee1d55
 
ee1d55
 	result = isc_ht_iter_create(catzs->zones, &iter);
ee1d55
 	INSIST(result == ISC_R_SUCCESS);
ee1d55
@@ -1930,6 +1976,7 @@ dns_catz_prereconfig(dns_catz_zones_t *catzs) {
ee1d55
 	     result == ISC_R_SUCCESS;
ee1d55
 	     result = isc_ht_iter_next(iter))
ee1d55
 	{
ee1d55
+		dns_catz_zone_t *zone = NULL;
ee1d55
 		isc_ht_iter_current(iter, (void **) &zone);
ee1d55
 		zone->active = ISC_FALSE;
ee1d55
 	}
ee1d55
@@ -1942,7 +1989,8 @@ dns_catz_postreconfig(dns_catz_zones_t *catzs) {
ee1d55
 	isc_result_t result;
ee1d55
 	dns_catz_zone_t *newzone = NULL;
ee1d55
 	isc_ht_iter_t *iter = NULL;
ee1d55
-	dns_catz_zone_t *zone;
ee1d55
+
ee1d55
+	REQUIRE(DNS_CATZ_ZONES_VALID(catzs));
ee1d55
 
ee1d55
 	LOCK(&catzs->lock);
ee1d55
 	result = isc_ht_iter_create(catzs->zones, &iter);
ee1d55
@@ -1950,6 +1998,8 @@ dns_catz_postreconfig(dns_catz_zones_t *catzs) {
ee1d55
 	for (result = isc_ht_iter_first(iter);
ee1d55
 	     result == ISC_R_SUCCESS;)
ee1d55
 	{
ee1d55
+		dns_catz_zone_t *zone = NULL;
ee1d55
+
ee1d55
 		isc_ht_iter_current(iter, (void **) &zone);
ee1d55
 		if (zone->active == ISC_FALSE) {
ee1d55
 			char cname[DNS_NAME_FORMATSIZE];
ee1d55
@@ -1985,5 +2035,6 @@ dns_catz_postreconfig(dns_catz_zones_t *catzs) {
ee1d55
 
ee1d55
 isc_result_t
ee1d55
 dns_catz_get_iterator(dns_catz_zone_t *catz, isc_ht_iter_t **itp) {
ee1d55
+	REQUIRE(DNS_CATZ_ZONE_VALID(catz));
ee1d55
 	return (isc_ht_iter_create(catz->entries, itp));
ee1d55
 }
ee1d55
diff --git a/lib/dns/include/dns/catz.h b/lib/dns/include/dns/catz.h
ee1d55
index 6345e1e..789ad54 100644
ee1d55
--- a/lib/dns/include/dns/catz.h
ee1d55
+++ b/lib/dns/include/dns/catz.h
ee1d55
@@ -75,7 +75,7 @@ dns_catz_options_init(dns_catz_options_t *options);
ee1d55
  * Initialize 'options' to NULL values.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	options to be non NULL
ee1d55
+ * \li	'options' to be non NULL.
ee1d55
  */
ee1d55
 
ee1d55
 void
ee1d55
@@ -84,20 +84,20 @@ dns_catz_options_free(dns_catz_options_t *options, isc_mem_t *mctx);
ee1d55
  * Free 'options' contents into 'mctx'. ('options' itself is not freed.)
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	options to be non NULL
ee1d55
- * \li	mctx to be a valid memory context
ee1d55
+ * \li	'options' to be non NULL.
ee1d55
+ * \li	'mctx' to be a valid memory context.
ee1d55
  */
ee1d55
 
ee1d55
 isc_result_t
ee1d55
 dns_catz_options_copy(isc_mem_t *mctx, const dns_catz_options_t *opts,
ee1d55
 		      dns_catz_options_t *nopts);
ee1d55
 /*%<
ee1d55
- * Duplicate 'opts' into 'nopts', allocating space from 'mctx'
ee1d55
+ * Duplicate 'opts' into 'nopts', allocating space from 'mctx'.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	'mctx' to be a valid memory context
ee1d55
- * \li	'options' to be non NULL and valid options
ee1d55
- * \li	'nopts' to be non NULL
ee1d55
+ * \li	'mctx' to be a valid memory context.
ee1d55
+ * \li	'options' to be non NULL and valid options.
ee1d55
+ * \li	'nopts' to be non NULL.
ee1d55
  */
ee1d55
 
ee1d55
 isc_result_t
ee1d55
@@ -107,9 +107,9 @@ dns_catz_options_setdefault(isc_mem_t *mctx, const dns_catz_options_t *defaults,
ee1d55
  * Replace empty values in 'opts' with values from 'defaults'
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	mctx to be a valid memory context
ee1d55
- * \li	defaults to be non NULL and valid options
ee1d55
- * \li	opts to be non NULL
ee1d55
+ * \li	'mctx' to be a valid memory context.
ee1d55
+ * \li	'defaults' to be non NULL and valid options.
ee1d55
+ * \li	'opts' to be non NULL.
ee1d55
  */
ee1d55
 
ee1d55
 dns_name_t *
ee1d55
@@ -118,10 +118,10 @@ dns_catz_entry_getname(dns_catz_entry_t *entry);
ee1d55
  * Get domain name for 'entry'
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	entry to be non NULL
ee1d55
+ * \li	'entry' to be non NULL.
ee1d55
  *
ee1d55
  * Returns:
ee1d55
- * \li	domain name for entry
ee1d55
+ * \li	domain name for entry.
ee1d55
  */
ee1d55
 
ee1d55
 isc_result_t
ee1d55
@@ -131,9 +131,9 @@ dns_catz_entry_new(isc_mem_t *mctx, const dns_name_t *domain,
ee1d55
  * Allocate a new catz_entry on 'mctx', with the name 'domain'
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	mctx to be a valid memory context
ee1d55
- * \li	domain to be valid dns_name or NULL
ee1d55
- * \li	nentryp to be non NULL, *nentryp to be NULL
ee1d55
+ * \li	'mctx' to be a valid memory context.
ee1d55
+ * \li	'domain' to be valid dns_name or NULL.
ee1d55
+ * \li	'nentryp' to be non NULL, *nentryp to be NULL.
ee1d55
  *
ee1d55
  * Returns:
ee1d55
  * \li	ISC_R_SUCCESS on success
ee1d55
@@ -147,9 +147,9 @@ dns_catz_entry_copy(dns_catz_zone_t *zone, const dns_catz_entry_t *entry,
ee1d55
  * Allocate a new catz_entry and deep copy 'entry' into 'nentryp'.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	mctx to be a valid memory context
ee1d55
- * \li	entry to be non NULL
ee1d55
- * \li	nentryp to be non NULL, *nentryp to be NULL
ee1d55
+ * \li	'mctx' to be a valid memory context.
ee1d55
+ * \li	'entry' to be non NULL.
ee1d55
+ * \li	'nentryp' to be non NULL, *nentryp to be NULL.
ee1d55
  *
ee1d55
  * Returns:
ee1d55
  * \li	ISC_R_SUCCESS on success
ee1d55
@@ -162,8 +162,8 @@ dns_catz_entry_attach(dns_catz_entry_t *entry, dns_catz_entry_t **entryp);
ee1d55
  * Attach an entry
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	entry is not NULL
ee1d55
- * \li	entryp is not NULL, *entryp is NULL
ee1d55
+ * \li	'entry' is a valid dns_catz_entry_t.
ee1d55
+ * \li	'entryp' is not NULL and '*entryp' is NULL.
ee1d55
  */
ee1d55
 
ee1d55
 void
ee1d55
@@ -172,8 +172,8 @@ dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp);
ee1d55
  * Detach an entry, free if no further references
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	zone is not NULL
ee1d55
- * \li	entryp is not NULL, *entryp is not NULL
ee1d55
+ * \li	'zone' is a valid dns_catz_zone_t.
ee1d55
+ * \li	'entryp' is not NULL and '*entryp' is not NULL.
ee1d55
  */
ee1d55
 
ee1d55
 isc_boolean_t
ee1d55
@@ -181,6 +181,9 @@ dns_catz_entry_validate(const dns_catz_entry_t *entry);
ee1d55
 /*%<
ee1d55
  * Validate whether entry is correct.
ee1d55
  * (NOT YET IMPLEMENTED: always returns true)
ee1d55
+ *
ee1d55
+ * Requires:
ee1d55
+ *\li	'entry' is a valid dns_catz_entry_t.
ee1d55
  */
ee1d55
 
ee1d55
 isc_boolean_t
ee1d55
@@ -189,12 +192,12 @@ dns_catz_entry_cmp(const dns_catz_entry_t *ea, const dns_catz_entry_t *eb);
ee1d55
  * Deep compare two entries
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	ea is not NULL
ee1d55
- * \li	eb is not NULL
ee1d55
+ * \li	'ea' is a valid dns_catz_entry_t.
ee1d55
+ * \li	'eb' is a valid dns_catz_entry_t.
ee1d55
  *
ee1d55
  * Returns:
ee1d55
- * \li ISC_TRUE if entries are the same
ee1d55
- * \li ISC_FALSE if the entries differ
ee1d55
+ * \li 'ISC_TRUE' if entries are the same.
ee1d55
+ * \li 'ISC_FALSE' if the entries differ.
ee1d55
  */
ee1d55
 
ee1d55
 void
ee1d55
@@ -203,8 +206,8 @@ dns_catz_zone_attach(dns_catz_zone_t *zone, dns_catz_zone_t **zonep);
ee1d55
  * Attach a catzone
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	zone is not NULL
ee1d55
- * \li	zonep is not NULL, *zonep is NULL
ee1d55
+ * \li	'zone' is a valid dns_catz_zone_t.
ee1d55
+ * \li	'zonep' is not NULL and '*zonep' is NULL.
ee1d55
  */
ee1d55
 
ee1d55
 void
ee1d55
@@ -213,7 +216,7 @@ dns_catz_zone_detach(dns_catz_zone_t** zonep);
ee1d55
  * Detach a zone, free if no further references
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	zonep is not NULL, *zonep is not NULL
ee1d55
+ * \li	'zonep' is not NULL and '*zonep' is not NULL.
ee1d55
  */
ee1d55
 
ee1d55
 isc_result_t
ee1d55
@@ -223,9 +226,9 @@ dns_catz_new_zone(dns_catz_zones_t *catzs, dns_catz_zone_t **zonep,
ee1d55
  * Allocate a new catz zone on catzs mctx
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	catzs is not NULL
ee1d55
- * \li	zonep is not NULL, *zonep is NULL
ee1d55
- * \li	name is not NULL
ee1d55
+ * \li	'catzs' is a valid dns_catz_zones_t.
ee1d55
+ * \li	'zonep' is not NULL and '*zonep' is NULL.
ee1d55
+ * \li	'name' is a valid dns_name_t.
ee1d55
  *
ee1d55
  */
ee1d55
 
ee1d55
@@ -235,7 +238,7 @@ dns_catz_zone_getname(dns_catz_zone_t *zone);
ee1d55
  * Get catalog zone name
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	zone is not NULL
ee1d55
+ * \li	'zone' is a valid dns_catz_zone_t.
ee1d55
  */
ee1d55
 
ee1d55
 dns_catz_options_t *
ee1d55
@@ -244,7 +247,7 @@ dns_catz_zone_getdefoptions(dns_catz_zone_t *zone);
ee1d55
  * Get default member zone options for catalog zone 'zone'
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	zone is not NULL
ee1d55
+ * \li	'zone' is a valid dns_catz_zone_t.
ee1d55
  */
ee1d55
 
ee1d55
 void
ee1d55
@@ -254,7 +257,7 @@ dns_catz_zone_resetdefoptions(dns_catz_zone_t *zone);
ee1d55
  * the default values.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	zone is not NULL
ee1d55
+ * \li	'zone' is a valid dns_catz_zone_t.
ee1d55
  */
ee1d55
 
ee1d55
 isc_result_t
ee1d55
@@ -264,8 +267,8 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone);
ee1d55
  * (from zone->catzs->zmm) for appropriate member zones.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	orig is not NULL
ee1d55
- * \li	newzone is not NULL, *newzone is not NULL
ee1d55
+ * \li	'orig' is a valid dns_catz_zone_t.
ee1d55
+ * \li	'newzone' is not NULL and '*newzone' is not NULL.
ee1d55
  *
ee1d55
  */
ee1d55
 
ee1d55
@@ -277,10 +280,10 @@ dns_catz_update_process(dns_catz_zones_t *catzs, dns_catz_zone_t *zone,
ee1d55
  * record name.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	catzs is not NULL
ee1d55
- * \li	zone is not NULL
ee1d55
- * \li	src_name is not NULL
ee1d55
- * \li	rdataset is valid
ee1d55
+ * \li	'catzs' is a valid dns_catz_zones_t.
ee1d55
+ * \li	'zone' is a valid dns_catz_zone_t.
ee1d55
+ * \li	'src_name' is a valid dns_name_t.
ee1d55
+ * \li	'rdataset' is valid rdataset.
ee1d55
  */
ee1d55
 
ee1d55
 isc_result_t
ee1d55
@@ -294,9 +297,9 @@ dns_catz_generate_masterfilename(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
ee1d55
  * __catz__unique_hash_generated_from_the_above.db
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	zone is not NULL
ee1d55
- * \li	entry is not NULL
ee1d55
- * \li	buffer is not NULL and *buffer is not NULL
ee1d55
+ * \li	'zone' is a valid dns_catz_zone_t.
ee1d55
+ * \li	'entry' is a valid dns_catz_entry_t.
ee1d55
+ * \li	'buffer' is not NULL and '*buffer' is not NULL.
ee1d55
  */
ee1d55
 
ee1d55
 isc_result_t
ee1d55
@@ -307,10 +310,9 @@ dns_catz_generate_zonecfg(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
ee1d55
  * it into *buf. buf might be reallocated.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	zone is not NULL
ee1d55
- * \li	entry is not NULL
ee1d55
- * \li	buf is not NULL
ee1d55
- * \li	*buf is NULL
ee1d55
+ * \li	'zone' is a valid dns_catz_zone_t.
ee1d55
+ * \li	'entry' is a valid dns_catz_entry_t.
ee1d55
+ * \li	'buf' is not NULL and '*buf' is NULL.
ee1d55
  *
ee1d55
  */
ee1d55
 
ee1d55
@@ -337,8 +339,8 @@ dns_catz_new_zones(dns_catz_zones_t **catzsp, dns_catz_zonemodmethods_t *zmm,
ee1d55
  * for a view.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li catzsp is not NULL, *catzsp is NULL
ee1d55
- * \li zmm is not NULL
ee1d55
+ * \li 'catzsp' is not NULL and '*catzsp' is NULL.
ee1d55
+ * \li 'zmm' is not NULL.
ee1d55
  *
ee1d55
  */
ee1d55
 
ee1d55
@@ -349,9 +351,9 @@ dns_catz_add_zone(dns_catz_zones_t *catzs, const dns_name_t *name,
ee1d55
  * Allocate a new catz named 'name' and put it in 'catzs' collection.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	catzs is not NULL
ee1d55
- * \li	name is not NULL
ee1d55
- * \li	zonep is not NULL, *zonep is NULL
ee1d55
+ * \li	'catzs' is a valid dns_catz_zones_t.
ee1d55
+ * \li	'name' is a valid dns_name_t.
ee1d55
+ * \li	'zonep' is not NULL and *zonep is NULL.
ee1d55
  *
ee1d55
  */
ee1d55
 
ee1d55
@@ -361,37 +363,37 @@ dns_catz_get_zone(dns_catz_zones_t *catzs, const dns_name_t *name);
ee1d55
  * Returns a zone named 'name' from collection 'catzs'
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	catzs is not NULL
ee1d55
- * \li	name is not NULL
ee1d55
+ * \li	'catzs' is a valid dns_catz_zones_t.
ee1d55
+ * \li	'name' is a valid dns_name_t.
ee1d55
  */
ee1d55
 
ee1d55
 void
ee1d55
 dns_catz_catzs_attach(dns_catz_zones_t *catzs, dns_catz_zones_t **catzsp);
ee1d55
 /*%<
ee1d55
- * Attach 'catzs' to 'catzsp'
ee1d55
+ * Attach 'catzs' to 'catzsp'.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	catzs is not NULL
ee1d55
- * \li	catzsp is not NULL, *catzsp is NULL
ee1d55
+ * \li	'catzs' is a valid dns_catz_zones_t.
ee1d55
+ * \li	'catzsp' is not NULL and *catzsp is NULL.
ee1d55
  */
ee1d55
 
ee1d55
 void
ee1d55
 dns_catz_catzs_detach(dns_catz_zones_t **catzsp);
ee1d55
 /*%<
ee1d55
- * Detach 'catzsp', free if no further references
ee1d55
+ * Detach 'catzsp', free if no further references.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	catzsp is not NULL, *catzsp is not NULL
ee1d55
+ * \li	'catzsp' is not NULL and *catzsp is not NULL.
ee1d55
  */
ee1d55
 
ee1d55
 void
ee1d55
 dns_catz_catzs_set_view(dns_catz_zones_t *catzs, dns_view_t *view);
ee1d55
 /*%<
ee1d55
- * Set a view for catzs
ee1d55
+ * Set a view for 'catzs'.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	catzs is not NULL
ee1d55
- * \li	catzs->view is NULL or catzs->view == view
ee1d55
+ * \li	'catzs' is a valid dns_catz_zones_t.
ee1d55
+ * \li	'catzs->view' is NULL or 'catzs->view' == 'view'.
ee1d55
  */
ee1d55
 
ee1d55
 
ee1d55
@@ -406,17 +408,17 @@ dns_catz_dbupdate_callback(dns_db_t *db, void *fn_arg);
ee1d55
  * If there is an update scheduled it replaces old db version with a new one.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	db is a valid database
ee1d55
- * \li	fn_arg is not NULL (casted to dns_catz_zones_t*)
ee1d55
+ * \li	'db' is a valid database.
ee1d55
+ * \li	'fn_arg' is not NULL (casted to dns_catz_zones_t*).
ee1d55
  */
ee1d55
 
ee1d55
 void
ee1d55
 dns_catz_update_taskaction(isc_task_t *task, isc_event_t *event);
ee1d55
 /*%<
ee1d55
- * Task that launches dns_catz_update_from_db
ee1d55
+ * Task that launches dns_catz_update_from_db.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	event is not NULL
ee1d55
+ * \li	'event' is not NULL.
ee1d55
  */
ee1d55
 
ee1d55
 void
ee1d55
@@ -427,8 +429,8 @@ dns_catz_update_from_db(dns_db_t *db, dns_catz_zones_t *catzs);
ee1d55
  * then merges new catz into old catz.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	db is a valid DB
ee1d55
- * \li	catzs is not NULL
ee1d55
+ * \li	'db' is a valid DB.
ee1d55
+ * \li	'catzs' is a valid dns_catz_zones_t.
ee1d55
  *
ee1d55
  */
ee1d55
 
ee1d55
@@ -438,7 +440,7 @@ dns_catz_prereconfig(dns_catz_zones_t *catzs);
ee1d55
  * Called before reconfig, clears 'active' flag on all the zones in set
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	catzs is not NULL
ee1d55
+ * \li	'catzs' is a valid dns_catz_zones_t.
ee1d55
  *
ee1d55
  */
ee1d55
 
ee1d55
@@ -449,7 +451,7 @@ dns_catz_postreconfig(dns_catz_zones_t *catzs);
ee1d55
  * inactive and force reload of those with changed configuration.
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	catzs is not NULL
ee1d55
+ * \li	'catzs' is a valid dns_catz_zones_t.
ee1d55
  */
ee1d55
 
ee1d55
 isc_result_t
ee1d55
@@ -457,6 +459,10 @@ dns_catz_get_iterator(dns_catz_zone_t *catz, isc_ht_iter_t **itp);
ee1d55
 /*%<
ee1d55
  * Get the hashtable iterator on catalog zone members, point '*itp' to it.
ee1d55
  *
ee1d55
+ * Requires:
ee1d55
+ * \li	'catzs' is a valid dns_catz_zones_t.
ee1d55
+ * \li	'itp' is not NULL and '*itp' is NULL.
ee1d55
+ *
ee1d55
  * Returns:
ee1d55
  * \li #ISC_R_SUCCESS		-- success
ee1d55
  * \li Any other value		-- failure
ee1d55
diff --git a/lib/isc/ht.c b/lib/isc/ht.c
ee1d55
index 5719394..a86e3ec 100644
ee1d55
--- a/lib/isc/ht.c
ee1d55
+++ b/lib/isc/ht.c
ee1d55
@@ -161,7 +161,7 @@ isc_ht_find(const isc_ht_t *ht, const unsigned char *key,
ee1d55
 
ee1d55
 	REQUIRE(ISC_HT_VALID(ht));
ee1d55
 	REQUIRE(key != NULL && keysize > 0);
ee1d55
-	REQUIRE(valuep != NULL);
ee1d55
+	REQUIRE(valuep == NULL || *valuep == NULL);
ee1d55
 
ee1d55
 	hash = isc_hash_function(key, keysize, ISC_TRUE, NULL);
ee1d55
 	node = ht->table[hash & ht->mask];
ee1d55
@@ -325,6 +325,8 @@ void
ee1d55
 isc_ht_iter_current(isc_ht_iter_t *it, void **valuep) {
ee1d55
 	REQUIRE(it != NULL);
ee1d55
 	REQUIRE(it->cur != NULL);
ee1d55
+	REQUIRE(valuep != NULL && *valuep == NULL);
ee1d55
+
ee1d55
 	*valuep = it->cur->value;
ee1d55
 }
ee1d55
 
ee1d55
@@ -333,6 +335,8 @@ isc_ht_iter_currentkey(isc_ht_iter_t *it, unsigned char **key, size_t *keysize)
ee1d55
 {
ee1d55
 	REQUIRE(it != NULL);
ee1d55
 	REQUIRE(it->cur != NULL);
ee1d55
+	REQUIRE(key != NULL && *key == NULL);
ee1d55
+
ee1d55
 	*key = it->cur->key;
ee1d55
 	*keysize = it->cur->keysize;
ee1d55
 }
ee1d55
diff --git a/lib/isc/include/isc/ht.h b/lib/isc/include/isc/ht.h
ee1d55
index 6ca4481..ea9eab7 100644
ee1d55
--- a/lib/isc/include/isc/ht.h
ee1d55
+++ b/lib/isc/include/isc/ht.h
ee1d55
@@ -25,10 +25,9 @@ typedef struct isc_ht_iter isc_ht_iter_t;
ee1d55
  * Initialize hashtable at *htp, using memory context and size of (1<
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- *\li	htp is not NULL
ee1d55
- *\li	*htp is NULL
ee1d55
- *\li	mctx is a valid memory context
ee1d55
- *\li	bits >=1 && bits <=32
ee1d55
+ *\li	'htp' is not NULL and '*htp' is NULL.
ee1d55
+ *\li	'mctx' is a valid memory context.
ee1d55
+ *\li	'bits' >=1 and 'bits' <=32
ee1d55
  *
ee1d55
  * Returns:
ee1d55
  *\li	#ISC_R_NOMEMORY		-- not enough memory to create pool
ee1d55
@@ -41,7 +40,7 @@ isc_ht_init(isc_ht_t **htp, isc_mem_t *mctx, isc_uint8_t bits);
ee1d55
  * Destroy hashtable, freeing everything
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- * \li	*htp is valid hashtable
ee1d55
+ * \li	'*htp' is valid hashtable
ee1d55
  */
ee1d55
 void
ee1d55
 isc_ht_destroy(isc_ht_t **htp);
ee1d55
@@ -51,7 +50,7 @@ isc_ht_destroy(isc_ht_t **htp);
ee1d55
  * set its value to 'value'
ee1d55
  *
ee1d55
  * Requires:
ee1d55
- *\li	ht is a valid hashtable
ee1d55
+ *\li	'ht' is a valid hashtable
ee1d55
  *
ee1d55
  * Returns:
ee1d55
  *\li	#ISC_R_NOMEMORY		-- not enough memory to create pool
ee1d55
@@ -79,6 +78,7 @@ isc_ht_find(const isc_ht_t *ht, const unsigned char *key,
ee1d55
 
ee1d55
 /*%
ee1d55
  * Delete node from hashtable
ee1d55
+ *
ee1d55
  * Requires:
ee1d55
  *\li	ht is a valid hashtable
ee1d55
  *
ee1d55
@@ -91,12 +91,19 @@ isc_ht_delete(isc_ht_t *ht, const unsigned char *key, isc_uint32_t keysize);
ee1d55
 
ee1d55
 /*%
ee1d55
  * Create an iterator for the hashtable; point '*itp' to it.
ee1d55
+ *
ee1d55
+ * Requires:
ee1d55
+ *\li	'ht' is a valid hashtable
ee1d55
+ *\li	'itp' is non NULL and '*itp' is NULL.
ee1d55
  */
ee1d55
 isc_result_t
ee1d55
 isc_ht_iter_create(isc_ht_t *ht, isc_ht_iter_t **itp);
ee1d55
 
ee1d55
 /*%
ee1d55
  * Destroy the iterator '*itp', set it to NULL
ee1d55
+ *
ee1d55
+ * Requires:
ee1d55
+ *\li	'itp' is non NULL and '*itp' is non NULL.
ee1d55
  */
ee1d55
 void
ee1d55
 isc_ht_iter_destroy(isc_ht_iter_t **itp);
ee1d55
@@ -104,6 +111,9 @@ isc_ht_iter_destroy(isc_ht_iter_t **itp);
ee1d55
 /*%
ee1d55
  * Set an iterator to the first entry.
ee1d55
  *
ee1d55
+ * Requires:
ee1d55
+ *\li	'it' is non NULL.
ee1d55
+ *
ee1d55
  * Returns:
ee1d55
  * \li 	#ISC_R_SUCCESS	-- success
ee1d55
  * \li	#ISC_R_NOMORE	-- no data in the hashtable
ee1d55
@@ -114,6 +124,9 @@ isc_ht_iter_first(isc_ht_iter_t *it);
ee1d55
 /*%
ee1d55
  * Set an iterator to the next entry.
ee1d55
  *
ee1d55
+ * Requires:
ee1d55
+ *\li	'it' is non NULL.
ee1d55
+ *
ee1d55
  * Returns:
ee1d55
  * \li 	#ISC_R_SUCCESS	-- success
ee1d55
  * \li	#ISC_R_NOMORE	-- end of hashtable reached
ee1d55
@@ -124,6 +137,9 @@ isc_ht_iter_next(isc_ht_iter_t *it);
ee1d55
 /*%
ee1d55
  * Delete current entry and set an iterator to the next entry.
ee1d55
  *
ee1d55
+ * Requires:
ee1d55
+ *\li	'it' is non NULL.
ee1d55
+ *
ee1d55
  * Returns:
ee1d55
  * \li 	#ISC_R_SUCCESS	-- success
ee1d55
  * \li	#ISC_R_NOMORE	-- end of hashtable reached
ee1d55
@@ -134,6 +150,10 @@ isc_ht_iter_delcurrent_next(isc_ht_iter_t *it);
ee1d55
 
ee1d55
 /*%
ee1d55
  * Set 'value' to the current value under the iterator
ee1d55
+ *
ee1d55
+ * Requires:
ee1d55
+ *\li	'it' is non NULL.
ee1d55
+ *\li   'valuep' is non NULL and '*valuep' is NULL.
ee1d55
  */
ee1d55
 void
ee1d55
 isc_ht_iter_current(isc_ht_iter_t *it, void **valuep);
ee1d55
@@ -141,6 +161,11 @@ isc_ht_iter_current(isc_ht_iter_t *it, void **valuep);
ee1d55
 /*%
ee1d55
  * Set 'key' and 'keysize to the current key and keysize for the value
ee1d55
  * under the iterator
ee1d55
+ *
ee1d55
+ * Requires:
ee1d55
+ *\li	'it' is non NULL.
ee1d55
+ *\li   'key' is non NULL and '*key' is NULL.
ee1d55
+ *\li	'keysize' is non NULL.
ee1d55
  */
ee1d55
 void
ee1d55
 isc_ht_iter_currentkey(isc_ht_iter_t *it, unsigned char **key, size_t *keysize);
ee1d55
diff --git a/lib/isc/tests/ht_test.c b/lib/isc/tests/ht_test.c
ee1d55
index 4b069ef..11ffb79 100644
ee1d55
--- a/lib/isc/tests/ht_test.c
ee1d55
+++ b/lib/isc/tests/ht_test.c
ee1d55
@@ -194,11 +194,9 @@ static void test_ht_iterator() {
ee1d55
 	isc_mem_t *mctx = NULL;
ee1d55
 	isc_ht_iter_t * iter = NULL;
ee1d55
 	uintptr_t i;
ee1d55
-	void *v;
ee1d55
 	uintptr_t count = 10000;
ee1d55
 	isc_uint32_t walked;
ee1d55
 	unsigned char key[16];
ee1d55
-	unsigned char *tkey;
ee1d55
 	size_t tksize;
ee1d55
 
ee1d55
 	result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
ee1d55
@@ -227,6 +225,9 @@ static void test_ht_iterator() {
ee1d55
 	     result == ISC_R_SUCCESS;
ee1d55
 	     result = isc_ht_iter_next(iter))
ee1d55
 	{
ee1d55
+		unsigned char *tkey = NULL;
ee1d55
+		void *v = NULL;
ee1d55
+
ee1d55
 		isc_ht_iter_current(iter, &v);
ee1d55
 		isc_ht_iter_currentkey(iter, &tkey, &tksize);
ee1d55
 		ATF_REQUIRE_EQ(tksize, 16);
ee1d55
@@ -243,6 +244,9 @@ static void test_ht_iterator() {
ee1d55
 	walked = 0;
ee1d55
 	result = isc_ht_iter_first(iter);
ee1d55
 	while (result == ISC_R_SUCCESS) {
ee1d55
+		unsigned char *tkey = NULL;
ee1d55
+		void *v = NULL;
ee1d55
+
ee1d55
 		isc_ht_iter_current(iter, &v);
ee1d55
 		isc_ht_iter_currentkey(iter, &tkey, &tksize);
ee1d55
 		ATF_REQUIRE_EQ(tksize, 16);
ee1d55
@@ -264,6 +268,9 @@ static void test_ht_iterator() {
ee1d55
 	walked = 0;
ee1d55
 	result = isc_ht_iter_first(iter);
ee1d55
 	while (result == ISC_R_SUCCESS) {
ee1d55
+		unsigned char *tkey = NULL;
ee1d55
+		void *v = NULL;
ee1d55
+
ee1d55
 		isc_ht_iter_current(iter, &v);
ee1d55
 		isc_ht_iter_currentkey(iter, &tkey, &tksize);
ee1d55
 		ATF_REQUIRE_EQ(tksize, 16);
ee1d55
-- 
ee1d55
2.45.0
ee1d55