From c48979e6c5a31b2fea2e81573e79bc77774cfc82 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Tue, 27 Aug 2019 22:41:18 -0700 Subject: [PATCH 1/2] simplify dns_rbtnodechain_init() by removing unnecessary 'mctx' parameter --- bin/named/server.c | 4 ++-- bin/tests/optional/rbt_test.c | 4 ++-- lib/dns/include/dns/rbt.h | 5 +---- lib/dns/keytable.c | 4 ++-- lib/dns/nta.c | 4 ++-- lib/dns/rbt.c | 6 ++---- lib/dns/rbtdb.c | 14 +++++++------- lib/dns/tests/rbt_test.c | 6 +++--- lib/dns/tsig.c | 4 ++-- lib/dns/zt.c | 6 +++--- 10 files changed, 26 insertions(+), 31 deletions(-) diff --git a/bin/named/server.c b/bin/named/server.c index 11a9bd4844..53ed19a58e 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -11488,7 +11488,7 @@ delete_keynames(dns_tsig_keyring_t *ring, char *target, origin = dns_fixedname_initname(&fixedorigin); again: - dns_rbtnodechain_init(&chain, ring->mctx); + dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, ring->keys, &foundname, origin); if (result == ISC_R_NOTFOUND) { @@ -11604,7 +11604,7 @@ list_keynames(dns_view_t *view, dns_tsig_keyring_t *ring, isc_buffer_t **text, dns_name_init(&foundname, NULL); origin = dns_fixedname_initname(&fixedorigin); - dns_rbtnodechain_init(&chain, ring->mctx); + dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, ring->keys, &foundname, origin); if (result == ISC_R_NOTFOUND) { diff --git a/bin/tests/optional/rbt_test.c b/bin/tests/optional/rbt_test.c index 17c5ae0386..404c019778 100644 --- a/bin/tests/optional/rbt_test.c +++ b/bin/tests/optional/rbt_test.c @@ -103,7 +103,7 @@ detail(dns_rbt_t *rbt, dns_name_t *name) { isc_result_t result; bool nodes_should_match = false; - dns_rbtnodechain_init(&chain, mctx); + dns_rbtnodechain_init(&chain); origin = dns_fixedname_initname(&fixedorigin); fullname = dns_fixedname_initname(&fixedfullname); @@ -182,7 +182,7 @@ iterate(dns_rbt_t *rbt, bool forward) { isc_result_t (*move)(dns_rbtnodechain_t *chain, dns_name_t *name, dns_name_t *origin); - dns_rbtnodechain_init(&chain, mctx); + dns_rbtnodechain_init(&chain); dns_name_init(&foundname, NULL); origin = dns_fixedname_initname(&fixedorigin); diff --git a/lib/dns/include/dns/rbt.h b/lib/dns/include/dns/rbt.h index c7f6a7c992..3e18e71c84 100644 --- a/lib/dns/include/dns/rbt.h +++ b/lib/dns/include/dns/rbt.h @@ -241,7 +241,6 @@ typedef void (*dns_rbtdeleter_t)(void *, void *); typedef struct dns_rbtnodechain { unsigned int magic; - isc_mem_t * mctx; /*% * The terminal node of the chain. It is not in levels[]. * This is ostensibly private ... but in a pinch it could be @@ -837,15 +836,13 @@ dns__rbtnode_getdistance(dns_rbtnode_t *node); *****/ void -dns_rbtnodechain_init(dns_rbtnodechain_t *chain, isc_mem_t *mctx); +dns_rbtnodechain_init(dns_rbtnodechain_t *chain); /*%< * Initialize 'chain'. * * Requires: *\li 'chain' is a valid pointer. * - *\li 'mctx' is a valid memory context. - * * Ensures: *\li 'chain' is suitable for use. */ diff --git a/lib/dns/keytable.c b/lib/dns/keytable.c index bd7b18068a..73e6cec89b 100644 --- a/lib/dns/keytable.c +++ b/lib/dns/keytable.c @@ -664,7 +664,7 @@ dns_keytable_totext(dns_keytable_t *keytable, isc_buffer_t **text) { REQUIRE(text != NULL && *text != NULL); RWLOCK(&keytable->rwlock, isc_rwlocktype_read); - dns_rbtnodechain_init(&chain, keytable->mctx); + dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, keytable->table, NULL, NULL); if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { if (result == ISC_R_NOTFOUND) @@ -713,7 +713,7 @@ dns_keytable_forall(dns_keytable_t *keytable, REQUIRE(VALID_KEYTABLE(keytable)); RWLOCK(&keytable->rwlock, isc_rwlocktype_read); - dns_rbtnodechain_init(&chain, keytable->mctx); + dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, keytable->table, NULL, NULL); if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { if (result == ISC_R_NOTFOUND) diff --git a/lib/dns/nta.c b/lib/dns/nta.c index 6b44857d9e..428a40d319 100644 --- a/lib/dns/nta.c +++ b/lib/dns/nta.c @@ -504,7 +504,7 @@ dns_ntatable_totext(dns_ntatable_t *ntatable, const char *view, isc_stdtime_get(&now); RWLOCK(&ntatable->rwlock, isc_rwlocktype_read); - dns_rbtnodechain_init(&chain, ntatable->view->mctx); + dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, ntatable->table, NULL, NULL); if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { if (result == ISC_R_NOTFOUND) @@ -603,7 +603,7 @@ dns_ntatable_save(dns_ntatable_t *ntatable, FILE *fp) { isc_stdtime_get(&now); RWLOCK(&ntatable->rwlock, isc_rwlocktype_read); - dns_rbtnodechain_init(&chain, ntatable->view->mctx); + dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, ntatable->table, NULL, NULL); if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) goto cleanup; diff --git a/lib/dns/rbt.c b/lib/dns/rbt.c index e806c01bb5..70f81c47e5 100644 --- a/lib/dns/rbt.c +++ b/lib/dns/rbt.c @@ -1462,7 +1462,7 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, if (chain == NULL) { options |= DNS_RBTFIND_NOPREDECESSOR; chain = &localchain; - dns_rbtnodechain_init(chain, rbt->mctx); + dns_rbtnodechain_init(chain); } else dns_rbtnodechain_reset(chain); @@ -3121,14 +3121,12 @@ dns_rbt_printdot(dns_rbt_t *rbt, bool show_pointers, FILE *f) { */ void -dns_rbtnodechain_init(dns_rbtnodechain_t *chain, isc_mem_t *mctx) { - +dns_rbtnodechain_init(dns_rbtnodechain_t *chain) { REQUIRE(chain != NULL); /* * Initialize 'chain'. */ - chain->mctx = mctx; chain->end = NULL; chain->level_count = 0; chain->level_matches = 0; diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c index b8922a5791..3277822091 100644 --- a/lib/dns/rbtdb.c +++ b/lib/dns/rbtdb.c @@ -3410,7 +3410,7 @@ find_wildcard(rbtdb_search_t *search, dns_rbtnode_t **nodep, break; wnode = NULL; - dns_rbtnodechain_init(&wchain, NULL); + dns_rbtnodechain_init(&wchain); result = dns_rbt_findnode(rbtdb->tree, wname, NULL, &wnode, &wchain, DNS_RBTFIND_EMPTYDATA, @@ -3548,7 +3548,7 @@ previous_closest_nsec(dns_rdatatype_t type, rbtdb_search_t *search, * It is the first node sought in the NSEC tree. */ *firstp = false; - dns_rbtnodechain_init(nsecchain, NULL); + dns_rbtnodechain_init(nsecchain); result = dns_name_concatenate(name, origin, target, NULL); if (result != ISC_R_SUCCESS) @@ -3862,7 +3862,7 @@ zone_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, search.wild = false; search.zonecut = NULL; dns_fixedname_init(&search.zonecut_name); - dns_rbtnodechain_init(&search.chain, search.rbtdb->common.mctx); + dns_rbtnodechain_init(&search.chain); search.now = 0; /* @@ -4739,7 +4739,7 @@ cache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, search.wild = false; search.zonecut = NULL; dns_fixedname_init(&search.zonecut_name); - dns_rbtnodechain_init(&search.chain, search.rbtdb->common.mctx); + dns_rbtnodechain_init(&search.chain); search.now = now; update = NULL; updatesig = NULL; @@ -5079,7 +5079,7 @@ cache_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options, search.wild = false; search.zonecut = NULL; dns_fixedname_init(&search.zonecut_name); - dns_rbtnodechain_init(&search.chain, search.rbtdb->common.mctx); + dns_rbtnodechain_init(&search.chain); search.now = now; if (dcnull) { @@ -5434,8 +5434,8 @@ createiterator(dns_db_t *db, unsigned int options, dns_dbiterator_t **iteratorp) rbtdbiter->nsec3only = ((options & DNS_DB_NSEC3ONLY) != 0); rbtdbiter->nonsec3 = ((options & DNS_DB_NONSEC3) != 0); memset(rbtdbiter->deletions, 0, sizeof(rbtdbiter->deletions)); - dns_rbtnodechain_init(&rbtdbiter->chain, db->mctx); - dns_rbtnodechain_init(&rbtdbiter->nsec3chain, db->mctx); + dns_rbtnodechain_init(&rbtdbiter->chain); + dns_rbtnodechain_init(&rbtdbiter->nsec3chain); if (rbtdbiter->nsec3only) rbtdbiter->current = &rbtdbiter->nsec3chain; else diff --git a/lib/dns/tests/rbt_test.c b/lib/dns/tests/rbt_test.c index 7c2657698c..bd00202638 100644 --- a/lib/dns/tests/rbt_test.c +++ b/lib/dns/tests/rbt_test.c @@ -292,7 +292,7 @@ rbtnode_get_distance(void **state) { dns_test_namefromstring(name_str, &fname); name = dns_fixedname_name(&fname); - dns_rbtnodechain_init(&chain, dt_mctx); + dns_rbtnodechain_init(&chain); result = dns_rbt_findnode(ctx->rbt_distances, name, NULL, &node, &chain, 0, NULL, NULL); @@ -730,7 +730,7 @@ rbt_remove(void **state) { tree_ok = dns__rbt_checkproperties(mytree); assert_true(tree_ok); - dns_rbtnodechain_init(&chain, dt_mctx); + dns_rbtnodechain_init(&chain); /* Now, walk through nodes in order. */ if (j == 0) { @@ -1157,7 +1157,7 @@ rbt_nodechain(void **state) { ctx = test_context_setup(); - dns_rbtnodechain_init(&chain, dt_mctx); + dns_rbtnodechain_init(&chain); dns_test_namefromstring("a", &fname); name = dns_fixedname_name(&fname); diff --git a/lib/dns/tsig.c b/lib/dns/tsig.c index 9c7fcb4b03..a350178648 100644 --- a/lib/dns/tsig.c +++ b/lib/dns/tsig.c @@ -408,7 +408,7 @@ cleanup_ring(dns_tsig_keyring_t *ring) origin = dns_fixedname_initname(&fixedorigin); again: - dns_rbtnodechain_init(&chain, ring->mctx); + dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, ring->keys, &foundname, origin); if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { @@ -614,7 +614,7 @@ dns_tsigkeyring_dumpanddetach(dns_tsig_keyring_t **ringp, FILE *fp) { isc_stdtime_get(&now); dns_name_init(&foundname, NULL); origin = dns_fixedname_initname(&fixedorigin); - dns_rbtnodechain_init(&chain, ring->mctx); + dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, ring->keys, &foundname, origin); if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { diff --git a/lib/dns/zt.c b/lib/dns/zt.c index 8c63ed1de8..69e1f10e6f 100644 --- a/lib/dns/zt.c +++ b/lib/dns/zt.c @@ -433,7 +433,7 @@ dns_zt_setviewcommit(dns_zt_t *zt) { REQUIRE(VALID_ZT(zt)); - dns_rbtnodechain_init(&chain, zt->mctx); + dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, zt->table, NULL, NULL); while (result == DNS_R_NEWORIGIN || result == ISC_R_SUCCESS) { @@ -457,7 +457,7 @@ dns_zt_setviewrevert(dns_zt_t *zt) { REQUIRE(VALID_ZT(zt)); - dns_rbtnodechain_init(&chain, zt->mctx); + dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, zt->table, NULL, NULL); while (result == DNS_R_NEWORIGIN || result == ISC_R_SUCCESS) { @@ -485,7 +485,7 @@ dns_zt_apply(dns_zt_t *zt, bool stop, isc_result_t *sub, REQUIRE(VALID_ZT(zt)); REQUIRE(action != NULL); - dns_rbtnodechain_init(&chain, zt->mctx); + dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, zt->table, NULL, NULL); if (result == ISC_R_NOTFOUND) { /* From a8595262f761392bef1a3bae50e84e2a2c6d4fdb Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Wed, 28 Aug 2019 21:10:10 -0700 Subject: [PATCH 2/2] add a semantic patch for the API change --- cocci/dns_rbtnodechain_init.spatch | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 cocci/dns_rbtnodechain_init.spatch diff --git a/cocci/dns_rbtnodechain_init.spatch b/cocci/dns_rbtnodechain_init.spatch new file mode 100644 index 0000000000..1c02a8335d --- /dev/null +++ b/cocci/dns_rbtnodechain_init.spatch @@ -0,0 +1,7 @@ +@@ +expression C; +expression M; +@@ + +- dns_rbtnodechain_init(C, M); ++ dns_rbtnodechain_init(C);