return (ISC_R_SUCCESS);
}
-#define grow_array(mctx, array, newlen, oldlen) \
- if (newlen >= oldlen) { \
- size_t newsize = (newlen + 16) * sizeof(array[0]); \
- size_t oldsize = oldlen * sizeof(array[0]); \
- void *tmp = isc_mem_get(mctx, newsize); \
- memset(tmp, 0, newsize); \
- if (oldlen != 0) { \
- memmove(tmp, array, oldsize); \
- isc_mem_put(mctx, array, oldsize); \
- } \
- array = tmp; \
- oldlen = newlen + 16; \
+#define grow_array(mctx, array, newlen, oldlen) \
+ if (newlen >= oldlen) { \
+ size_t newsize = (newlen + 16) * sizeof(array[0]); \
+ size_t oldsize = oldlen * sizeof(array[0]); \
+ array = isc_mem_regetx(mctx, array, oldsize, newsize, \
+ ISC_MEM_ZERO); \
+ oldlen = newlen + 16; \
}
-#define shrink_array(mctx, array, newlen, oldlen) \
- if (newlen < oldlen) { \
- void *tmp = NULL; \
- size_t newsize = newlen * sizeof(array[0]); \
- size_t oldsize = oldlen * sizeof(array[0]); \
- if (newlen != 0) { \
- tmp = isc_mem_getx(mctx, newsize, ISC_MEM_ZERO); \
- memmove(tmp, array, newsize); \
- } else { \
- tmp = NULL; \
- } \
- isc_mem_put(mctx, array, oldsize); \
- array = tmp; \
- oldlen = newlen; \
+#define shrink_array(mctx, array, newlen, oldlen) \
+ if (newlen < oldlen) { \
+ size_t newsize = newlen * sizeof(array[0]); \
+ size_t oldsize = oldlen * sizeof(array[0]); \
+ array = isc_mem_regetx(mctx, array, oldsize, newsize, \
+ ISC_MEM_ZERO); \
+ oldlen = newlen; \
}
isc_result_t
*/
acl->magic = DNS_ACL_MAGIC;
- acl->elements = isc_mem_getx(mctx, n * sizeof(dns_aclelement_t),
+ acl->elements = isc_mem_getx(mctx, n * sizeof(acl->elements[0]),
ISC_MEM_ZERO);
acl->alloc = n;
ISC_LIST_INIT(acl->ports_and_transports);
isc_result_t
dns_acl_merge(dns_acl_t *dest, dns_acl_t *source, bool pos) {
isc_result_t result;
- unsigned int newalloc, nelem, i;
+ unsigned int nelem, i;
int max_node = 0, nodes;
/* Resize the element array if needed. */
if (dest->length + source->length > dest->alloc) {
- void *newmem;
-
- newalloc = dest->alloc + source->alloc;
+ size_t newalloc = dest->alloc + source->alloc;
if (newalloc < 4) {
newalloc = 4;
}
- newmem = isc_mem_getx(dest->mctx,
- newalloc * sizeof(dns_aclelement_t),
- ISC_MEM_ZERO);
-
- /* Copy in the original elements */
- memmove(newmem, dest->elements,
- dest->length * sizeof(dns_aclelement_t));
-
- /* Release the memory for the old elements array */
- isc_mem_put(dest->mctx, dest->elements,
- dest->alloc * sizeof(dns_aclelement_t));
- dest->elements = newmem;
+ dest->elements = isc_mem_regetx(
+ dest->mctx, dest->elements,
+ dest->alloc * sizeof(dest->elements[0]),
+ newalloc * sizeof(dest->elements[0]), ISC_MEM_ZERO);
dest->alloc = newalloc;
}
}
if (dacl->elements != NULL) {
isc_mem_put(dacl->mctx, dacl->elements,
- dacl->alloc * sizeof(dns_aclelement_t));
+ dacl->alloc * sizeof(dacl->elements[0]));
}
if (dacl->name != NULL) {
isc_mem_free(dacl->mctx, dacl->name);
dns_resolver_disable_algorithm(dns_resolver_t *resolver, const dns_name_t *name,
unsigned int alg) {
unsigned int len, mask;
- unsigned char *tmp;
- unsigned char *algorithms;
isc_result_t result;
dns_rbtnode_t *node = NULL;
+ unsigned char *algorithms = NULL;
+ unsigned int algorithms_len;
/*
* Whether an algorithm is disabled (or not) is stored in a
result = dns_rbt_create(resolver->mctx, free_algorithm,
resolver->mctx, &resolver->algorithms);
if (result != ISC_R_SUCCESS) {
- goto cleanup;
+ return (result);
}
}
result = dns_rbt_addnode(resolver->algorithms, name, &node);
- if (result == ISC_R_SUCCESS || result == ISC_R_EXISTS) {
- algorithms = node->data;
+ if (result != ISC_R_SUCCESS && result != ISC_R_EXISTS) {
+ return (result);
+ }
+
+ /* If algorithms is set, algorithms[0] contains its length. */
+ algorithms = node->data;
+ algorithms_len = (algorithms) ? algorithms[0] : 0;
+
+ if (algorithms == NULL || len > algorithms_len) {
+ INSIST(len > 0);
/*
- * If algorithms is set, algorithms[0] contains its
- * length.
+ * If no bitfield exists in the node data, or if
+ * it is not long enough, allocate a new
+ * bitfield and copy the old (smaller) bitfield
+ * into it if one exists.
*/
- if (algorithms == NULL || len > *algorithms) {
- /*
- * If no bitfield exists in the node data, or if
- * it is not long enough, allocate a new
- * bitfield and copy the old (smaller) bitfield
- * into it if one exists.
- */
- tmp = isc_mem_getx(resolver->mctx, len, ISC_MEM_ZERO);
- if (algorithms != NULL) {
- memmove(tmp, algorithms, *algorithms);
- }
- tmp[len - 1] |= mask;
- /* tmp[0] should contain the length of 'tmp'. */
- *tmp = len;
- node->data = tmp;
- /* Free the older bitfield. */
- if (algorithms != NULL) {
- isc_mem_put(resolver->mctx, algorithms,
- *algorithms);
- }
- } else {
- algorithms[len - 1] |= mask;
- }
+ node->data = algorithms =
+ isc_mem_regetx(resolver->mctx, algorithms,
+ algorithms_len, len, ISC_MEM_ZERO);
+ /* store the new length */
+ algorithms[0] = len;
}
- result = ISC_R_SUCCESS;
-cleanup:
- return (result);
+
+ algorithms[len - 1] |= mask;
+ return (ISC_R_SUCCESS);
}
bool