]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
zone: tell apart an empty zone and other errors
authorDavid Vašek <david.vasek@nic.cz>
Tue, 31 Aug 2021 07:58:05 +0000 (09:58 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Tue, 7 Sep 2021 13:37:00 +0000 (15:37 +0200)
src/knot/zone/contents.c
src/knot/zone/contents.h
src/knot/zone/digest.c
src/knot/zone/digest.h
src/knot/zone/semantic-check.c
src/knot/zone/semantic-check.h
src/knot/zone/zone-diff.c
src/knot/zone/zone-dump.c
src/knot/zone/zone-load.c
src/knot/zone/zone.c
src/knot/zone/zonefile.c

index 898fc2d05e5ba4307330d748ee895c736fd5a2cb..d267adb91f3b2246c296fb603a9386619b68f5b0 100644 (file)
@@ -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;
        }
 
index 92841a67f4bebfe5a1982c96638d6cc3cd0d0de4..0f2c3da5290a495511ede5e4e40b5280d551ef4f 100644 (file)
@@ -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
  */
index 1b7a4669d90aeab5195aed91ebcc5d1dad359f79..8587c8be4f96d16823325ced13ea567ab0951124 100644 (file)
@@ -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);
index e153da0cb85ba2b21e5642b6779939d9173b195b..f136476ae547a1e98585a7d4d7770f4f2f49dd2b 100644 (file)
@@ -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.
index e67d669d21db0bae49158198aa6babba5d69e7ad..710adb1c6238997279650ddbae1daf0fc43dc2fc 100644 (file)
@@ -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,
index c11149f746116e51d8e90e5fd7ad56c2da06b00f..6c9d2b3825e3834fd6005ce4e1ea0cd29f4dc6da 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2020 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2021 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
@@ -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);
index cf6d8c72c08d9568b1a2b0d43d01f6bb9134ae1d..59d86f1276e272e6b88d809da0eb2f46fd6ef4d8 100644 (file)
@@ -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;
index dc6b0914dbf5ceee20d15303cb1e8ea6e05f3bf9..37070ba5b53eb956ef3e442b46a97b7350e8a175 100644 (file)
@@ -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) {
index 93ee1e459ec7f6cb54408110c643254e07c23d21..ab41b151a451aac01c58102c73b2fd5d38352e89 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2020 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2021 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,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;
index 07958dda63463c56a48d2caf130874d34b0fbd91..a827eb0e34800756b2484a8c6be660adb1669b77 100644 (file)
@@ -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);
index 026a9370e90aae61cefe525355dba70063b38fc7..fc26b3bc1c726e1c0f75a47c8e9634193b8bbf59 100644 (file)
@@ -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;