Commit 610d4b81 authored by Daniel Salzman's avatar Daniel Salzman

knot: don't sanitize input pointer in node_free

parent 1a141beb
......@@ -166,7 +166,7 @@ static void free_nsec3_tree(zone_tree_t *nodes)
knot_rdataset_t *rrsig = node_rdataset(node, KNOT_RRTYPE_RRSIG);
knot_rdataset_clear(nsec3, NULL);
knot_rdataset_clear(rrsig, NULL);
node_free(&node, NULL);
node_free(node, NULL);
}
trie_it_free(it);
......@@ -302,14 +302,14 @@ static zone_node_t *create_nsec3_node(const knot_dname_t *owner,
int ret = create_nsec3_rrset(&nsec3_rrset, owner, nsec3_params,
rr_types, NULL, ttl);
if (ret != KNOT_EOK) {
node_free(&new_node, NULL);
node_free(new_node, NULL);
return NULL;
}
ret = node_add_rrset(new_node, &nsec3_rrset, NULL);
knot_rrset_clear(&nsec3_rrset, NULL);
if (ret != KNOT_EOK) {
node_free(&new_node, NULL);
node_free(new_node, NULL);
return NULL;
}
......@@ -638,7 +638,7 @@ static int fix_nsec3_for_node(zone_update_t *update, const dnssec_nsec3_params_t
}
}
node_free_rrsets(new_nsec3_n, NULL);
node_free(&new_nsec3_n, NULL);
node_free(new_nsec3_n, NULL);
}
return ret;
......
......@@ -565,12 +565,12 @@ static int process_rem_node(const knot_rrset_t *rr,
knot_rrset_t rrset = node_rrset_at(node_copy, rrset_count - i - 1);
int ret = process_rem_rrset(&rrset, node_copy, update);
if (ret != KNOT_EOK) {
node_free(&node_copy, NULL);
node_free(node_copy, NULL);
return ret;
}
}
node_free(&node_copy, NULL);
node_free(node_copy, NULL);
return KNOT_EOK;
}
......
......@@ -87,7 +87,7 @@ static int destroy_node_rrsets_from_tree(zone_node_t **node, void *data)
if (*node != NULL) {
node_free_rrsets(*node, NULL);
node_free(node, NULL);
node_free(*node, NULL);
}
return KNOT_EOK;
......@@ -488,7 +488,7 @@ static int add_node(zone_contents_t *zone, zone_node_t *node, bool create_parent
/* Insert node to a tree. */
ret = zone_tree_insert(zone->nodes, next_node);
if (ret != KNOT_EOK) {
node_free(&next_node, NULL);
node_free(next_node, NULL);
return ret;
}
......@@ -577,7 +577,7 @@ static int insert_rr(zone_contents_t *z, const knot_rrset_t *rr,
}
int ret = nsec3 ? add_nsec3_node(z, *n) : add_node(z, *n, true);
if (ret != KNOT_EOK) {
node_free(n, NULL);
node_free(*n, NULL);
}
}
}
......@@ -644,7 +644,7 @@ static int recreate_normal_tree(const zone_contents_t *z, zone_contents_t *out)
// Normal additions need apex ... so we need to insert directly.
int ret = zone_tree_insert(out->nodes, apex_cpy);
if (ret != KNOT_EOK) {
node_free(&apex_cpy, NULL);
node_free(apex_cpy, NULL);
return ret;
}
......@@ -670,7 +670,7 @@ static int recreate_normal_tree(const zone_contents_t *z, zone_contents_t *out)
int ret = add_node(out, to_add, true);
if (ret != KNOT_EOK) {
node_free(&to_add, NULL);
node_free(to_add, NULL);
trie_it_free(itt);
return ret;
}
......@@ -704,7 +704,7 @@ static int recreate_nsec3_tree(const zone_contents_t *z, zone_contents_t *out)
int ret = add_nsec3_node(out, to_add);
if (ret != KNOT_EOK) {
trie_it_free(itt);
node_free(&to_add, NULL);
node_free(to_add, NULL);
return ret;
}
......@@ -751,7 +751,7 @@ zone_node_t *zone_contents_get_node_for_rr(zone_contents_t *zone, const knot_rrs
node = node_new(rrset->owner, NULL);
int ret = nsec3 ? add_nsec3_node(zone, node) : add_node(zone, node, true);
if (ret != KNOT_EOK) {
node_free(&node, NULL);
node_free(node, NULL);
return NULL;
}
......
......@@ -120,20 +120,19 @@ void node_free_rrsets(zone_node_t *node, knot_mm_t *mm)
node->rrset_count = 0;
}
void node_free(zone_node_t **node, knot_mm_t *mm)
void node_free(zone_node_t *node, knot_mm_t *mm)
{
if (node == NULL || *node == NULL) {
if (node == NULL) {
return;
}
if ((*node)->rrs != NULL) {
mm_free(mm, (*node)->rrs);
}
knot_dname_free(node->owner, mm);
knot_dname_free((*node)->owner, mm);
if (node->rrs != NULL) {
mm_free(mm, node->rrs);
}
mm_free(mm, *node);
*node = NULL;
mm_free(mm, node);
}
zone_node_t *node_shallow_copy(const zone_node_t *src, knot_mm_t *mm)
......@@ -155,7 +154,7 @@ zone_node_t *node_shallow_copy(const zone_node_t *src, knot_mm_t *mm)
size_t rrlen = sizeof(struct rr_data) * src->rrset_count;
dst->rrs = mm_alloc(mm, rrlen);
if (dst->rrs == NULL) {
node_free(&dst, mm);
node_free(dst, mm);
return NULL;
}
memcpy(dst->rrs, src->rrs, rrlen);
......
......@@ -112,12 +112,11 @@ void node_free_rrsets(zone_node_t *node, knot_mm_t *mm);
* \brief Destroys the node structure.
*
* Does not destroy the data within the node.
* Also sets the given pointer to NULL.
*
* \param node Node to be destroyed.
* \param mm Memory context to use.
*/
void node_free(zone_node_t **node, knot_mm_t *mm);
void node_free(zone_node_t *node, knot_mm_t *mm);
/*!
* \brief Creates a shallow copy of node structure, RR data are shared.
......
......@@ -160,7 +160,7 @@ void zone_tree_delete_empty(zone_tree_t *tree, zone_node_t *node)
// Delete node
remove_node(tree, node->owner);
node_free(&node, NULL);
node_free(node, NULL);
}
}
......@@ -192,7 +192,7 @@ static int zone_tree_free_node(zone_node_t **node, void *data)
UNUSED(data);
if (node) {
node_free(node, NULL);
node_free(*node, NULL);
}
return KNOT_EOK;
......
......@@ -62,7 +62,7 @@ int main(int argc, char *argv[])
node_set_parent(node, parent);
ok(node->parent == parent && parent->children == 1, "Node: set parent.");
node_free(&parent, NULL);
node_free(parent, NULL);
// Test RRSet addition
knot_rrset_t *dummy_rrset = create_dummy_rrset(dummy_owner, KNOT_RRTYPE_TXT);
......@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
copy->flags == node->flags;
ok(copy_ok, "Node: shallow copy - set fields.");
node_free(&copy, NULL);
node_free(copy, NULL);
// Test RRSet getters
knot_rrset_t *n_rrset = node_create_rrset(node, KNOT_RRTYPE_TXT);
......@@ -146,8 +146,7 @@ int main(int argc, char *argv[])
node_free_rrsets(node, NULL);
ok(node->rrset_count == 0, "Node: free RRSets.");
node_free(&node, NULL);
ok(node == NULL, "Node: free.");
node_free(node, NULL);
knot_dname_free(dummy_owner, NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment