2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Use isc_mem_regetx() when appropriate

While refactoring the isc_mem_getx(...) usage, couple places were
identified where the memory was resized manually.  Use the
isc_mem_reget(...) that was introduced in [GL !5440] to resize the
arrays via function rather than a custom code.
This commit is contained in:
Ondřej Surý
2022-08-26 11:58:51 +02:00
parent c0598d404c
commit e18b6fb6a6
3 changed files with 49 additions and 79 deletions

View File

@@ -11110,10 +11110,10 @@ isc_result_t
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
@@ -11130,7 +11130,7 @@ dns_resolver_disable_algorithm(dns_resolver_t *resolver, const dns_name_t *name,
result = dns_rbt_create(resolver->mctx, free_algorithm,
resolver->mctx, &resolver->algorithms);
if (result != ISC_R_SUCCESS) {
goto cleanup;
return (result);
}
}
@@ -11139,39 +11139,31 @@ dns_resolver_disable_algorithm(dns_resolver_t *resolver, const dns_name_t *name,
result = dns_rbt_addnode(resolver->algorithms, name, &node);
if (result == ISC_R_SUCCESS || result == ISC_R_EXISTS) {
algorithms = node->data;
/*
* If algorithms is set, algorithms[0] contains its
* length.
*/
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;
}
if (result != ISC_R_SUCCESS && result != ISC_R_EXISTS) {
return (result);
}
result = ISC_R_SUCCESS;
cleanup:
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 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.
*/
node->data = algorithms =
isc_mem_regetx(resolver->mctx, algorithms,
algorithms_len, len, ISC_MEM_ZERO);
/* store the new length */
algorithms[0] = len;
}
algorithms[len - 1] |= mask;
return (ISC_R_SUCCESS);
}
bool