From 704b9ee9d08c47740fe2401900b65f188ef07fe2 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 30 Jan 2020 18:55:36 +1100 Subject: [PATCH] skip if first is NULL --- lib/dns/zoneverify.c | 75 +++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/lib/dns/zoneverify.c b/lib/dns/zoneverify.c index c19367b0a0..4f9264356d 100644 --- a/lib/dns/zoneverify.c +++ b/lib/dns/zoneverify.c @@ -1122,7 +1122,7 @@ free_element_heap(void *element, void *uap) { } static bool -checknext(const vctx_t *vctx, const struct nsec3_chain_fixed *first, +_checknext(const vctx_t *vctx, const struct nsec3_chain_fixed *first, const struct nsec3_chain_fixed *e) { char buf[512]; @@ -1162,6 +1162,37 @@ checknext(const vctx_t *vctx, const struct nsec3_chain_fixed *first, return (false); } +static inline bool +checknext(isc_mem_t *mctx, + const vctx_t *vctx, + const struct nsec3_chain_fixed *first, + struct nsec3_chain_fixed *prev, + const struct nsec3_chain_fixed *cur) +{ + bool result = _checknext(vctx, prev, cur); + + if (prev != first) { + free_element(mctx, prev); + } + + return (result); +} + +static inline bool +checklast(isc_mem_t *mctx, + const vctx_t *vctx, + struct nsec3_chain_fixed *first, + struct nsec3_chain_fixed *prev) +{ + bool result = _checknext(vctx, prev, first); + if (prev != first) { + free_element(mctx, prev); + } + free_element(mctx, first); + + return (result); +} + static isc_result_t verify_nsec3_chains(const vctx_t *vctx, isc_mem_t *mctx) { isc_result_t result = ISC_R_SUCCESS; @@ -1214,39 +1245,27 @@ verify_nsec3_chains(const vctx_t *vctx, isc_mem_t *mctx) { "not equal"); result = ISC_R_FAILURE; } - if (first == NULL || newchain(first, e)) { - if (prev != NULL) { - if (!checknext(vctx, prev, first)) { - result = ISC_R_FAILURE; - } - if (prev != first) { - free_element(mctx, prev); - } - } - if (first != NULL) { - free_element(mctx, first); - } + + if (first == NULL) { prev = first = e; - continue; + } else if (newchain(first, e)) { + if (!checklast(mctx, vctx, first, prev)) { + result = ISC_R_FAILURE; + } + + prev = first = e; + } else { + if (!checknext(mctx, vctx, first, prev, e)) { + result = ISC_R_FAILURE; + } + + prev = e; } - if (!checknext(vctx, prev, e)) { - result = ISC_R_FAILURE; - } - if (prev != first) { - free_element(mctx, prev); - } - prev = e; } if (prev != NULL) { - if (!checknext(vctx, prev, first)) { + if (!checklast(mctx, vctx, first, prev)) { result = ISC_R_FAILURE; } - if (prev != first) { - free_element(mctx, prev); - } - } - if (first != NULL) { - free_element(mctx, first); } do { if (f != NULL) {