errors initalizing badcaches were not caught or cleaned up on error paths

(cherry picked from commit 93776c4c81)
This commit is contained in:
Mark Andrews 2018-11-09 15:31:26 +11:00 committed by Evan Hunt
parent 5b4905d428
commit 3aafdbf160
2 changed files with 35 additions and 14 deletions

View file

@ -8889,8 +8889,11 @@ dns_resolver_create(dns_view_t *view,
res->algorithms = NULL;
res->digests = NULL;
res->badcache = NULL;
dns_badcache_init(res->mctx, DNS_RESOLVER_BADCACHESIZE,
&res->badcache);
result = dns_badcache_init(res->mctx, DNS_RESOLVER_BADCACHESIZE,
&res->badcache);
if (result != ISC_R_SUCCESS) {
goto cleanup_res;
}
res->mustbesecure = NULL;
res->spillatmin = res->spillat = 10;
res->spillatmax = 100;
@ -8911,7 +8914,7 @@ dns_resolver_create(dns_view_t *view,
ntasks * sizeof(fctxbucket_t));
if (res->buckets == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup_res;
goto cleanup_badcache;
}
for (i = 0; i < ntasks; i++) {
result = isc_mutex_init(&res->buckets[i].lock);
@ -9080,6 +9083,9 @@ dns_resolver_create(dns_view_t *view,
isc_mem_put(view->mctx, res->buckets,
res->nbuckets * sizeof(fctxbucket_t));
cleanup_badcache:
dns_badcache_destroy(&res->badcache);
cleanup_res:
isc_mem_put(view->mctx, res, sizeof(*res));

View file

@ -250,15 +250,19 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
view->cfg_destroy = NULL;
view->fail_ttl = 0;
view->failcache = NULL;
(void)dns_badcache_init(view->mctx, DNS_VIEW_FAILCACHESIZE,
result = dns_badcache_init(view->mctx, DNS_VIEW_FAILCACHESIZE,
&view->failcache);
if (result != ISC_R_SUCCESS) {
goto cleanup_dynkeys;
}
view->v6bias = 0;
view->dtenv = NULL;
view->dttypes = 0;
result = isc_mutex_init(&view->new_zone_lock);
if (result != ISC_R_SUCCESS)
goto cleanup_dynkeys;
if (result != ISC_R_SUCCESS) {
goto cleanup_failcache;
}
if (isc_bind9) {
result = dns_order_create(view->mctx, &view->order);
@ -267,12 +271,14 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
}
result = dns_peerlist_new(view->mctx, &view->peers);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup_order;
}
result = dns_aclenv_init(view->mctx, &view->aclenv);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup_peerlist;
}
ISC_LINK_INIT(view, link);
ISC_EVENT_INIT(&view->resevent, sizeof(view->resevent), 0, NULL,
@ -292,37 +298,46 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
return (ISC_R_SUCCESS);
cleanup_peerlist:
if (view->peers != NULL)
if (view->peers != NULL) {
dns_peerlist_detach(&view->peers);
}
cleanup_order:
if (view->order != NULL)
if (view->order != NULL) {
dns_order_detach(&view->order);
}
cleanup_new_zone_lock:
DESTROYLOCK(&view->new_zone_lock);
cleanup_failcache:
dns_badcache_destroy(&view->failcache);
cleanup_dynkeys:
if (view->dynamickeys != NULL)
if (view->dynamickeys != NULL) {
dns_tsigkeyring_detach(&view->dynamickeys);
}
cleanup_references:
isc_refcount_decrement(&view->references, NULL);
isc_refcount_destroy(&view->references);
cleanup_fwdtable:
if (view->fwdtable != NULL)
if (view->fwdtable != NULL) {
dns_fwdtable_destroy(&view->fwdtable);
}
cleanup_zt:
if (view->zonetable != NULL)
if (view->zonetable != NULL) {
dns_zt_detach(&view->zonetable);
}
cleanup_mutex:
DESTROYLOCK(&view->lock);
if (view->nta_file != NULL)
if (view->nta_file != NULL) {
isc_mem_free(mctx, view->nta_file);
}
cleanup_name:
isc_mem_free(mctx, view->name);