Commit 40e6c1f8 authored by Daniel Salzman's avatar Daniel Salzman

knot: don't sanitize input pointer in zone_contents_deep_free

parent 9af52bf5
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -33,7 +33,7 @@ int event_expire(conf_t *conf, zone_t *zone)
log_zone_info(zone->name, "zone expired");
synchronize_rcu();
zone_contents_deep_free(&expired);
zone_contents_deep_free(expired);
zone->zonefile.exists = false;
mem_trim();
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -88,7 +88,7 @@ int event_load(conf_t *conf, zone_t *zone)
(!old_contents_exist || zonefile_unchanged)) {
ret = zone_load_journal(conf, zone, zf_conts);
if (ret != KNOT_EOK) {
zone_contents_deep_free(&zf_conts);
zone_contents_deep_free(zf_conts);
log_zone_warning(zone->name, "failed to load journal (%s)",
knot_strerror(ret));
}
......@@ -130,10 +130,10 @@ int event_load(conf_t *conf, zone_t *zone)
log_zone_warning(zone->name, "zone file changed with SOA serial %s, "
"ignoring zone file and loading from journal",
(ret == KNOT_ESEMCHECK ? "unupdated" : "decreased"));
zone_contents_deep_free(&zf_conts);
zone_contents_deep_free(zf_conts);
ret = zone_update_from_contents(&up, zone, journal_conts, UPDATE_INCREMENTAL);
} else {
zone_contents_deep_free(&journal_conts);
zone_contents_deep_free(journal_conts);
}
}
} else {
......@@ -219,8 +219,8 @@ cleanup:
// Try to bootstrap the zone if local error.
replan_from_timers(conf, zone);
zone_contents_deep_free(&zf_conts);
zone_contents_deep_free(&journal_conts);
zone_contents_deep_free(zf_conts);
zone_contents_deep_free(journal_conts);
return (dontcare_load_error(conf, zone) ? KNOT_EOK : ret);
}
......@@ -205,7 +205,7 @@ static int axfr_init(struct refresh_data *data)
static void axfr_cleanup(struct refresh_data *data)
{
zone_contents_deep_free(&data->axfr.zone);
zone_contents_deep_free(data->axfr.zone);
}
static int axfr_finalize(struct refresh_data *data)
......
......@@ -541,10 +541,10 @@ int changeset_to_contents(changeset_t *ch, zone_contents_t **out)
int ret = add_rr_to_contents(*out, ch->soa_to);
knot_rrset_free(ch->soa_to, NULL);
if (ret != KNOT_EOK) {
zone_contents_deep_free(out);
zone_contents_deep_free(*out);
}
zone_contents_deep_free(&ch->remove);
zone_contents_deep_free(ch->remove);
free(ch->data);
free(ch);
return ret;
......@@ -564,7 +564,7 @@ changeset_t *changeset_from_contents(const zone_contents_t *contents)
node_remove_rdataset(copy->apex, KNOT_RRTYPE_SOA);
zone_contents_deep_free(&res->add);
zone_contents_deep_free(res->add);
res->add = copy;
return res;
}
......@@ -577,7 +577,7 @@ void changeset_from_contents_free(changeset_t *ch)
update_free_zone(&ch->add);
zone_contents_deep_free(&ch->remove);
zone_contents_deep_free(ch->remove);
knot_rrset_free(ch->soa_from, NULL);
knot_rrset_free(ch->soa_to, NULL);
free(ch->data);
......@@ -615,8 +615,10 @@ void changeset_clear(changeset_t *ch)
}
// Delete RRSets in lists, in case there are any left
zone_contents_deep_free(&ch->add);
zone_contents_deep_free(&ch->remove);
zone_contents_deep_free(ch->add);
zone_contents_deep_free(ch->remove);
ch->add = NULL;
ch->remove = NULL;
knot_rrset_free(ch->soa_from, NULL);
knot_rrset_free(ch->soa_to, NULL);
......
......@@ -282,7 +282,7 @@ void zone_update_clear(zone_update_t *update)
/* Revert any changes on error, do nothing on success. */
if (update->new_cont_deep_copy) {
update_cleanup(update->a_ctx);
zone_contents_deep_free(&update->new_cont);
zone_contents_deep_free(update->new_cont);
} else {
update_rollback(update->a_ctx);
update_free_zone(&update->new_cont);
......@@ -290,7 +290,7 @@ void zone_update_clear(zone_update_t *update)
changeset_clear(&update->change);
} else if (update->flags & UPDATE_FULL) {
assert(update->new_cont_deep_copy);
zone_contents_deep_free(&update->new_cont);
zone_contents_deep_free(update->new_cont);
}
free(update->a_ctx);
mp_delete(update->mm.ctx);
......
......@@ -1105,24 +1105,23 @@ void zone_contents_free(zone_contents_t *contents)
free(contents);
}
void zone_contents_deep_free(zone_contents_t **contents)
void zone_contents_deep_free(zone_contents_t *contents)
{
if (contents == NULL || *contents == NULL) {
if (contents == NULL) {
return;
}
if (*contents != NULL) {
if (contents != NULL) {
// Delete NSEC3 tree
(void)zone_tree_apply((*contents)->nsec3_nodes,
(void)zone_tree_apply(contents->nsec3_nodes,
destroy_node_rrsets_from_tree, NULL);
// Delete normal tree
(void)zone_tree_apply((*contents)->nodes,
(void)zone_tree_apply(contents->nodes,
destroy_node_rrsets_from_tree, NULL);
}
zone_contents_free(*contents);
*contents = NULL;
zone_contents_free(contents);
}
uint32_t zone_contents_serial(const zone_contents_t *zone)
......
......@@ -239,7 +239,7 @@ void zone_contents_free(zone_contents_t *contents);
*
* \param contents Zone contents to free.
*/
void zone_contents_deep_free(zone_contents_t **contents);
void zone_contents_deep_free(zone_contents_t *contents);
/*!
* \brief Fetch zone serial.
......
......@@ -258,7 +258,7 @@ void zone_free(zone_t **zone_ptr)
free(zone->preferred_master);
/* Free zone contents. */
zone_contents_deep_free(&zone->contents);
zone_contents_deep_free(zone->contents);
conf_deactivate_modules(&zone->query_modules, &zone->query_plan);
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -165,7 +165,7 @@ int zonefile_open(zloader_t *loader, const char *source,
/* Prepare textual owner for zone scanner. */
char *origin_str = knot_dname_to_str_alloc(origin);
if (origin_str == NULL) {
zone_contents_deep_free(&zc->z);
zone_contents_deep_free(zc->z);
free(zc);
return KNOT_ENOMEM;
}
......@@ -175,7 +175,7 @@ int zonefile_open(zloader_t *loader, const char *source,
zs_set_processing(&loader->scanner, process_data, process_error, zc) != 0) {
zs_deinit(&loader->scanner);
free(origin_str);
zone_contents_deep_free(&zc->z);
zone_contents_deep_free(zc->z);
free(zc);
return KNOT_EFILE;
}
......@@ -244,7 +244,7 @@ zone_contents_t *zonefile_load(zloader_t *loader)
return zc->z;
fail:
zone_contents_deep_free(&zc->z);
zone_contents_deep_free(zc->z);
return NULL;
}
......
......@@ -558,7 +558,7 @@ static int zone_check(const knot_dname_t *dname, void *data)
zone_contents_t *contents;
int ret = zone_load_contents(conf(), dname, &contents);
if (ret == KNOT_EOK) {
zone_contents_deep_free(&contents);
zone_contents_deep_free(contents);
}
return ret;
}
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -80,7 +80,7 @@ int zone_check(const char *zone_file, const knot_dname_t *zone_name,
if (contents == NULL && !stats.handler.fatal_error) {
return KNOT_ERROR;
}
zone_contents_deep_free(&contents);
zone_contents_deep_free(contents);
if (stats.error_count > 0) {
print_statistics(&stats);
......
......@@ -157,7 +157,7 @@ int main(int argc, char *argv[])
ret = changeset_preapply_fix(z, ch2);
ok(ret == KNOT_EOK, "changeset: preapply fix ok (%s)", knot_strerror(ret));
ok(changeset_empty(ch2), "changeset: preapply fix works");
zone_contents_deep_free(&z);
zone_contents_deep_free(z);
// Test cancelout.
ret = changeset_add_removal(ch2, apex_txt_rr, 0);
......
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