*/
};
+/*
+ * Helper function used to calculate length of variable-length
+ * data section in object pointed to by 'chain'.
+ */
+static inline size_t
+chain_length(struct nsec3_chain_fixed *chain) {
+ return (chain->salt_length + 2 * chain->next_length);
+}
+
/*%
* Log a zone verification error described by 'fmt' and the variable arguments
* following it. Either use dns_zone_logv() or print to stderr, depending on
static bool
chain_compare(void *arg1, void *arg2) {
struct nsec3_chain_fixed *e1 = arg1, *e2 = arg2;
- size_t len;
-
/*
* Do each element in turn to get a stable sort.
*/
if (e1->next_length > e2->next_length) {
return (false);
}
- len = e1->salt_length + 2 * e1->next_length;
- if (memcmp(e1 + 1, e2 + 1, len) < 0) {
+ if (memcmp(e1 + 1, e2 + 1, chain_length(e1)) < 0) {
return (true);
}
return (false);
static bool
chain_equal(const struct nsec3_chain_fixed *e1,
- const struct nsec3_chain_fixed *e2) {
- size_t len;
-
+ const struct nsec3_chain_fixed *e2, size_t data_length) {
if (e1->hash != e2->hash) {
return (false);
}
if (e1->next_length != e2->next_length) {
return (false);
}
- len = e1->salt_length + 2 * e1->next_length;
- if (memcmp(e1 + 1, e2 + 1, len) != 0) {
- return (false);
- }
- return (true);
+
+ return (memcmp(e1 + 1, e2 + 1, data_length) == 0);
}
static isc_result_t
return (nsec_exists ? ISC_R_FAILURE : ISC_R_SUCCESS);
}
-static bool
-newchain(const struct nsec3_chain_fixed *first,
- const struct nsec3_chain_fixed *e) {
- if (first->hash != e->hash || first->iterations != e->iterations ||
- first->salt_length != e->salt_length ||
- first->next_length != e->next_length ||
- memcmp(first + 1, e + 1, first->salt_length) != 0)
- {
- return (true);
- }
- return (false);
-}
-
static void
free_element(isc_mem_t *mctx, struct nsec3_chain_fixed *e) {
size_t len;
/*
* Check that they match.
*/
- if (chain_equal(e, f)) {
+ if (chain_equal(e, f, chain_length(e))) {
free_element(mctx, f);
f = NULL;
} else {
isc_heap_delete(
vctx->found_chains, 1);
}
- if (f != NULL && chain_equal(e, f)) {
+ if (f != NULL &&
+ chain_equal(e, f, chain_length(e)))
+ {
free_element(mctx, f);
f = NULL;
break;
if (first == NULL) {
prev = first = e;
- } else if (newchain(first, e)) {
+ } else if (!chain_equal(first, e, first->salt_length)) {
if (!checklast(mctx, vctx, first, prev)) {
result = ISC_R_FAILURE;
}