1baafe
From 0f03071080e7fa68433b322359d46abaca2cc5ad Mon Sep 17 00:00:00 2001
1baafe
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
1baafe
Date: Wed, 16 Jan 2019 16:27:33 +0100
1baafe
Subject: [PATCH] Fix possible crash when loading corrupted file
1baafe
1baafe
Some values passes internal triggers by coincidence. Fix the check and
1baafe
check also first_node_offset before even passing it further.
1baafe
---
1baafe
 lib/dns/rbt.c | 4 +++-
1baafe
 1 file changed, 3 insertions(+), 1 deletion(-)
1baafe
1baafe
diff --git a/lib/dns/rbt.c b/lib/dns/rbt.c
1baafe
index 5aee5f6..7f2c2d2 100644
1baafe
--- a/lib/dns/rbt.c
1baafe
+++ b/lib/dns/rbt.c
1baafe
@@ -945,7 +945,9 @@ dns_rbt_deserialize_tree(void *base_address, size_t filesize,
1baafe
 	rbt->root = (dns_rbtnode_t *)((char *)base_address + header_offset +
1baafe
 				      header->first_node_offset);
1baafe
 
1baafe
-	if ((header->nodecount * sizeof(dns_rbtnode_t)) > filesize) {
1baafe
+	if ((header->nodecount * sizeof(dns_rbtnode_t)) > filesize
1baafe
+	    || header->first_node_offset > filesize) {
1baafe
+
1baafe
 		result = ISC_R_INVALIDFILE;
1baafe
 		goto cleanup;
1baafe
 	}
1baafe
-- 
1baafe
2.31.1
1baafe