From: David VaĊĦek Date: Tue, 31 Aug 2021 07:58:05 +0000 (+0200) Subject: zone: tell apart an empty zone and other errors X-Git-Tag: v3.1.2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5f30e1858e5f07aeb70ad8cf347cda88222be33;p=thirdparty%2Fknot-dns.git zone: tell apart an empty zone and other errors --- diff --git a/src/knot/zone/contents.c b/src/knot/zone/contents.c index 898fc2d05e..d267adb91f 100644 --- a/src/knot/zone/contents.c +++ b/src/knot/zone/contents.c @@ -213,19 +213,27 @@ zone_tree_t *zone_contents_tree_for_rr(zone_contents_t *contents, const knot_rrs int zone_contents_add_rr(zone_contents_t *z, const knot_rrset_t *rr, zone_node_t **n) { - if (z == NULL || rr == NULL || n == NULL) { + if (rr == NULL || n == NULL) { return KNOT_EINVAL; } + if (z == NULL) { + return KNOT_EEMPTYZONE; + } + return insert_rr(z, rr, n); } int zone_contents_remove_rr(zone_contents_t *z, const knot_rrset_t *rr, zone_node_t **n) { - if (z == NULL || rr == NULL || n == NULL) { + if (rr == NULL || n == NULL) { return KNOT_EINVAL; } + if (z == NULL) { + return KNOT_EEMPTYZONE; + } + return remove_rr(z, rr, n, knot_rrset_is_nsec3rel(rr)); } @@ -268,10 +276,14 @@ int zone_contents_find_dname(const zone_contents_t *zone, const zone_node_t **closest, const zone_node_t **previous) { - if (!zone || !name || !match || !closest) { + if (name == NULL || match == NULL || closest == NULL) { return KNOT_EINVAL; } + if (zone == NULL) { + return KNOT_EEMPTYZONE; + } + if (knot_dname_in_bailiwick(name, zone->apex->owner) < 0) { return KNOT_EOUTOFZONE; } @@ -338,11 +350,14 @@ int zone_contents_find_nsec3_for_name(const zone_contents_t *zone, const zone_node_t **nsec3_node, const zone_node_t **nsec3_previous) { - if (zone == NULL || name == NULL || nsec3_node == NULL || - nsec3_previous == NULL) { + if (name == NULL || nsec3_node == NULL || nsec3_previous == NULL) { return KNOT_EINVAL; } + if (zone == NULL) { + return KNOT_EEMPTYZONE; + } + // check if the NSEC3 tree is not empty if (zone_tree_is_empty(zone->nsec3_nodes)) { return KNOT_ENSEC3CHAIN; @@ -427,7 +442,7 @@ int zone_contents_apply(zone_contents_t *contents, zone_tree_apply_cb_t function, void *data) { if (contents == NULL) { - return KNOT_EINVAL; + return KNOT_EEMPTYZONE; } return zone_tree_apply(contents->nodes, function, data); } @@ -436,17 +451,21 @@ int zone_contents_nsec3_apply(zone_contents_t *contents, zone_tree_apply_cb_t function, void *data) { if (contents == NULL) { - return KNOT_EINVAL; + return KNOT_EEMPTYZONE; } return zone_tree_apply(contents->nsec3_nodes, function, data); } int zone_contents_cow(const zone_contents_t *from, zone_contents_t **to) { - if (from == NULL || to == NULL) { + if (to == NULL) { return KNOT_EINVAL; } + if (from == NULL) { + return KNOT_EEMPTYZONE; + } + /* Copy to same destination as source. */ if (from == *to) { return KNOT_EINVAL; @@ -540,7 +559,11 @@ void zone_contents_set_soa_serial(zone_contents_t *zone, uint32_t new_serial) int zone_contents_load_nsec3param(zone_contents_t *contents) { - if (contents == NULL || contents->apex == NULL) { + if (contents == NULL) { + return KNOT_EEMPTYZONE; + } + + if (contents->apex == NULL) { return KNOT_EINVAL; } diff --git a/src/knot/zone/contents.h b/src/knot/zone/contents.h index 92841a67f4..0f2c3da529 100644 --- a/src/knot/zone/contents.h +++ b/src/knot/zone/contents.h @@ -123,6 +123,7 @@ zone_node_t *zone_contents_find_node_for_rr(zone_contents_t *contents, const kno * * \retval ZONE_NAME_FOUND if node with owner \a name was found. * \retval ZONE_NAME_NOT_FOUND if it was not found. + * \retval KNOT_EEMPTYZONE * \retval KNOT_EINVAL * \retval KNOT_EOUTOFZONE */ @@ -160,6 +161,7 @@ const zone_node_t *zone_contents_find_nsec3_node(const zone_contents_t *contents * * \retval ZONE_NAME_FOUND if the corresponding NSEC3 node was found. * \retval ZONE_NAME_NOT_FOUND if it was not found. + * \retval KNOT_EEMPTYZONE * \retval KNOT_EINVAL * \retval KNOT_ENSEC3PAR * \retval KNOT_ECRYPTO @@ -239,6 +241,7 @@ int zone_contents_nsec3_apply(zone_contents_t *contents, * \param to Copy of the zone. * * \retval KNOT_EOK + * \retval KNOT_EEMPTYZONE * \retval KNOT_EINVAL * \retval KNOT_ENOMEM */ diff --git a/src/knot/zone/digest.c b/src/knot/zone/digest.c index 1b7a4669d9..8587c8be4f 100644 --- a/src/knot/zone/digest.c +++ b/src/knot/zone/digest.c @@ -102,10 +102,14 @@ static int digest_node(zone_node_t *node, void *ctx) int zone_contents_digest(const zone_contents_t *contents, int algorithm, uint8_t **out_digest, size_t *out_size) { - if (contents == NULL || out_digest == NULL || out_size == NULL) { + if (out_digest == NULL || out_size == NULL) { return KNOT_EINVAL; } + if (contents == NULL) { + return KNOT_EEMPTYZONE; + } + contents_digest_ctx_t ctx = { .buf_size = DIGEST_BUF_MIN, .buf = malloc(DIGEST_BUF_MIN), @@ -187,7 +191,7 @@ static bool check_duplicate_schalg(const knot_rdataset_t *zonemd, int check_upto int zone_contents_digest_verify(const zone_contents_t *contents) { if (contents == NULL) { - return KNOT_EINVAL; + return KNOT_EEMPTYZONE; } knot_rdataset_t *zonemd = node_rdataset(contents->apex, KNOT_RRTYPE_ZONEMD); diff --git a/src/knot/zone/digest.h b/src/knot/zone/digest.h index e153da0cb8..f136476ae5 100644 --- a/src/knot/zone/digest.h +++ b/src/knot/zone/digest.h @@ -36,6 +36,7 @@ int zone_contents_digest(const zone_contents_t *contents, int algorithm, * * \param contents Zone contents ot be verified. * + * \retval KNOT_EEMPTYZONE The zone is empty. * \retval KNOT_ENOENT There is no ZONEMD in contents' apex. * \retval KNOT_ENOTSUP None of present ZONEMD is supported (scheme+algrithm+SOAserial). * \retval KNOT_ESEMCHECK Duplicate ZONEMD with identical scheme+algorithm pair. diff --git a/src/knot/zone/semantic-check.c b/src/knot/zone/semantic-check.c index e67d669d21..710adb1c62 100644 --- a/src/knot/zone/semantic-check.c +++ b/src/knot/zone/semantic-check.c @@ -1256,10 +1256,14 @@ static int unmark_nsec3_optout(zone_node_t *node, _unused_ void *ctx) int sem_checks_process(zone_contents_t *zone, semcheck_optional_t optional, sem_handler_t *handler, time_t time) { - if (zone == NULL || handler == NULL) { + if (handler == NULL) { return KNOT_EINVAL; } + if (zone == NULL) { + return KNOT_EEMPTYZONE; + } + semchecks_data_t data = { .handler = handler, .zone = zone, diff --git a/src/knot/zone/semantic-check.h b/src/knot/zone/semantic-check.h index c11149f746..6c9d2b3825 100644 --- a/src/knot/zone/semantic-check.h +++ b/src/knot/zone/semantic-check.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 CZ.NIC, z.s.p.o. +/* Copyright (C) 2021 CZ.NIC, z.s.p.o. 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 @@ -126,9 +126,10 @@ struct sem_handler { * \param handler Semantic error handler. * \param time Check zone at given time (rrsig expiration). * - * \retval KNOT_EOK no error found - * \retval KNOT_ESEMCHECK found semantic error - * \retval KNOT_EINVAL or other error + * \retval KNOT_EOK no error found + * \retval KNOT_ESEMCHECK found semantic error + * \retval KNOT_EEMPTYZONE the zone is empty + * \retval KNOT_EINVAL another error */ int sem_checks_process(zone_contents_t *zone, semcheck_optional_t optional, sem_handler_t *handler, time_t time); diff --git a/src/knot/zone/zone-diff.c b/src/knot/zone/zone-diff.c index cf6d8c72c0..59d86f1276 100644 --- a/src/knot/zone/zone-diff.c +++ b/src/knot/zone/zone-diff.c @@ -349,10 +349,14 @@ static int load_trees(zone_tree_t *nodes1, zone_tree_t *nodes2, int zone_contents_diff(const zone_contents_t *zone1, const zone_contents_t *zone2, changeset_t *changeset, bool ignore_dnssec) { - if (zone1 == NULL || zone2 == NULL || changeset == NULL) { + if (changeset == NULL) { return KNOT_EINVAL; } + if (zone1 == NULL || zone2 == NULL) { + return KNOT_EEMPTYZONE; + } + int ret_soa = load_soas(zone1, zone2, changeset); if (ret_soa != KNOT_EOK && ret_soa != KNOT_ENODIFF) { return ret_soa; diff --git a/src/knot/zone/zone-dump.c b/src/knot/zone/zone-dump.c index dc6b0914db..37070ba5b5 100644 --- a/src/knot/zone/zone-dump.c +++ b/src/knot/zone/zone-dump.c @@ -138,10 +138,14 @@ static int node_dump_text(zone_node_t *node, void *data) int zone_dump_text(zone_contents_t *zone, FILE *file, bool comments) { - if (zone == NULL || file == NULL) { + if (file == NULL) { return KNOT_EINVAL; } + if (zone == NULL) { + return KNOT_EEMPTYZONE; + } + // Allocate auxiliary buffer for dumping operations. char *buf = malloc(DUMP_BUF_LEN); if (buf == NULL) { diff --git a/src/knot/zone/zone-load.c b/src/knot/zone/zone-load.c index 93ee1e459e..ab41b151a4 100644 --- a/src/knot/zone/zone-load.c +++ b/src/knot/zone/zone-load.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 CZ.NIC, z.s.p.o. +/* Copyright (C) 2021 CZ.NIC, z.s.p.o. 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,10 +80,14 @@ static int apply_one_cb(bool remove, const knot_rrset_t *rr, void *ctx) int zone_load_journal(conf_t *conf, zone_t *zone, zone_contents_t *contents) { - if (conf == NULL || zone == NULL || contents == NULL) { + if (conf == NULL || zone == NULL) { return KNOT_EINVAL; } + if (contents == NULL) { + return KNOT_EEMPTYZONE; + } + // Check if journal is used (later in zone_changes_load() and zone is not empty. if (zone_contents_is_empty(contents)) { return KNOT_EOK; diff --git a/src/knot/zone/zone.c b/src/knot/zone/zone.c index 07958dda63..a827eb0e34 100644 --- a/src/knot/zone/zone.c +++ b/src/knot/zone/zone.c @@ -74,7 +74,7 @@ static int flush_journal(conf_t *conf, zone_t *zone, bool allow_empty_zone, bool if (allow_empty_zone && journal_is_existing(j)) { ret = journal_set_flushed(j); } else { - ret = KNOT_EINVAL; + ret = KNOT_EEMPTYZONE; } goto flush_journal_replan; } @@ -284,10 +284,14 @@ int zone_changes_clear(conf_t *conf, zone_t *zone) int zone_in_journal_store(conf_t *conf, zone_t *zone, zone_contents_t *new_contents) { - if (conf == NULL || zone == NULL || new_contents == NULL) { + if (conf == NULL || zone == NULL) { return KNOT_EINVAL; } + if (new_contents == NULL) { + return KNOT_EEMPTYZONE; + } + zone_journal_t j = { zone->journaldb, zone->name, conf }; int ret = journal_insert_zone(j, new_contents); diff --git a/src/knot/zone/zonefile.c b/src/knot/zone/zonefile.c index 026a9370e9..fc26b3bc1c 100644 --- a/src/knot/zone/zonefile.c +++ b/src/knot/zone/zonefile.c @@ -280,10 +280,14 @@ int zonefile_exists(const char *path, struct timespec *mtime) int zonefile_write(const char *path, zone_contents_t *zone) { - if (!zone || !path) { + if (path == NULL) { return KNOT_EINVAL; } + if (zone == NULL) { + return KNOT_EEMPTYZONE; + } + int ret = make_path(path, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP); if (ret != KNOT_EOK) { return ret;