]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
skip if first is NULL
authorMark Andrews <marka@isc.org>
Thu, 30 Jan 2020 07:55:36 +0000 (18:55 +1100)
committerOndřej Surý <ondrej@isc.org>
Tue, 4 Feb 2020 10:09:22 +0000 (11:09 +0100)
lib/dns/zoneverify.c

index c19367b0a0ec67225df4a53e17f408f9b21cb17f..4f9264356d2cdf323f6564ff0b01bd0a03e1e814 100644 (file)
@@ -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;
+               } else if (newchain(first, e)) {
+                       if (!checklast(mctx, vctx, first, prev)) {
+                               result = ISC_R_FAILURE;
                        }
+
                        prev = first = e;
-                       continue;
-               }
-               if (!checknext(vctx, prev, e)) {
-                       result = ISC_R_FAILURE;
-               }
-               if (prev != first) {
-                       free_element(mctx, prev);
+               } else {
+                       if (!checknext(mctx, vctx, first, prev, e)) {
+                               result = ISC_R_FAILURE;
+                       }
+
+                       prev = e;
                }
-               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) {