]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
skip if first is NULL
authorMark Andrews <marka@isc.org>
Wed, 5 Feb 2020 09:40:33 +0000 (10:40 +0100)
committerOndřej Surý <ondrej@isc.org>
Sat, 8 Feb 2020 14:32:42 +0000 (06:32 -0800)
(manually picked from 704b9ee9d08c47740fe2401900b65f188ef07fe2)

bin/dnssec/dnssectool.c

index 9d2a0169e79dfc6a12d62c324d9492716efe05f8..3ed8bb46c607188eea6e7748935c4826e623b5e1 100644 (file)
@@ -1333,7 +1333,7 @@ free_element(isc_mem_t *mctx, struct nsec3_chain_fixed *e) {
 }
 
 static bool
-checknext(const struct nsec3_chain_fixed *first,
+_checknext(const struct nsec3_chain_fixed *first,
          const struct nsec3_chain_fixed *e)
 {
        char buf[512];
@@ -1371,6 +1371,35 @@ checknext(const struct nsec3_chain_fixed *first,
        return (false);
 }
 
+static inline bool
+checknext(isc_mem_t *mctx,
+         const struct nsec3_chain_fixed *first,
+         struct nsec3_chain_fixed *prev,
+         const struct nsec3_chain_fixed *cur)
+{
+       bool result = _checknext(prev, cur);
+
+       if (prev != first) {
+               free_element(mctx, prev);
+       }
+
+       return (result);
+}
+
+static inline bool
+checklast(isc_mem_t *mctx,
+         struct nsec3_chain_fixed *first,
+         struct nsec3_chain_fixed *prev)
+{
+       bool result = _checknext(prev, first);
+       if (prev != first) {
+               free_element(mctx, prev);
+       }
+       free_element(mctx, first);
+
+       return (result);
+}
+
 #define EXPECTEDANDFOUND "Expected and found NSEC3 chains not equal\n"
 
 static isc_result_t
@@ -1415,32 +1444,27 @@ verify_nsec3_chains(isc_mem_t *mctx) {
                        fprintf(stderr, EXPECTEDANDFOUND);
                        result = ISC_R_FAILURE;
                }
-               if (first == NULL || newchain(first, e)) {
-                       if (prev != NULL) {
-                               if (!checknext(prev, first))
-                                       result = ISC_R_FAILURE;
-                               if (prev != first)
-                                       free_element(mctx, prev);
+
+               if (first == NULL) {
+                       prev = first = e;
+               } else if (newchain(first, e)) {
+                       if (!checklast(mctx, first, prev)) {
+                               result = ISC_R_FAILURE;
                        }
-                       if (first != NULL)
-                               free_element(mctx, first);
+
                        prev = first = e;
-                       continue;
+               } else {
+                       if (!checknext(mctx, first, prev, e)) {
+                               result = ISC_R_FAILURE;
+                       }
+
+                       prev = e;
                }
-               if (!checknext(prev, e))
-                       result = ISC_R_FAILURE;
-               if (prev != first)
-                       free_element(mctx, prev);
-               prev = e;
        }
        if (prev != NULL) {
-               if (!checknext(prev, first))
+               if (!checklast(mctx, first, prev))
                        result = ISC_R_FAILURE;
-               if (prev != first)
-                       free_element(mctx, prev);
        }
-       if (first != NULL)
-               free_element(mctx, first);
        do {
                if (f != NULL) {
                        if (result == ISC_R_SUCCESS) {