From b1f0b315f554c4566af722bdf1ed748d290b7a8c Mon Sep 17 00:00:00 2001
From: Lubos Slovak <lubos.slovak@nic.cz>
Date: Tue, 19 Jun 2012 17:02:04 +0200
Subject: [PATCH] Fixes to NSEC3 (NSEC3 node search and answering).

- In both cases check also if the NSEC3 tree is not empty. That
  may cause problems.

refs #1922, #1933, #1597
---
 src/libknot/zone/zone-contents.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/libknot/zone/zone-contents.c b/src/libknot/zone/zone-contents.c
index 92c8ae163b..abf9c3c9dd 100644
--- a/src/libknot/zone/zone-contents.c
+++ b/src/libknot/zone/zone-contents.c
@@ -1944,6 +1944,13 @@ int knot_zone_contents_find_nsec3_for_name(const knot_zone_contents_t *zone,
 		return ret;
 	}
 
+	// check if the NSEC3 tree is not empty
+	if (zone->nsec3_nodes->th_root == NULL) {
+		dbg_zone("NSEC3 tree is empty.\n");
+		knot_dname_release(nsec3_name);
+		return KNOT_ENSEC3CHAIN;
+	}
+
 dbg_zone_exec_verb(
 	char *n = knot_dname_to_str(nsec3_name);
 	dbg_zone_verb("NSEC3 node name: %s.\n", n);
@@ -2150,7 +2157,8 @@ int knot_zone_contents_nsec3_enabled(const knot_zone_contents_t *zone)
 		return KNOT_EBADARG;
 	}
 
-	return (zone->nsec3_params.algorithm != 0);
+	return (zone->nsec3_params.algorithm != 0
+	        && zone->nsec3_nodes->th_root != NULL);
 //	return (zone->nsec3_nodes->th_root != NULL);
 }
 
-- 
GitLab