685f10c
From 3bb29f45604ac6890f4ea5cdcbd1a62e6dad14a7 Mon Sep 17 00:00:00 2001
685f10c
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
685f10c
Date: Wed, 16 Jan 2019 16:27:33 +0100
685f10c
Subject: [PATCH 2/2] Fix possible crash when loading corrupted file
685f10c
685f10c
Some values passes internal triggers by coincidence. Fix the check and
685f10c
check also first_node_offset before even passing it further.
685f10c
---
685f10c
 lib/dns/rbt.c | 5 +++--
685f10c
 1 file changed, 3 insertions(+), 2 deletions(-)
685f10c
685f10c
diff --git a/lib/dns/rbt.c b/lib/dns/rbt.c
685f10c
index 62d0826..b029b7d 100644
685f10c
--- a/lib/dns/rbt.c
685f10c
+++ b/lib/dns/rbt.c
685f10c
@@ -787,7 +787,7 @@ treefix(dns_rbt_t *rbt, void *base, size_t filesize, dns_rbtnode_t *n,
685f10c
 		return (ISC_R_SUCCESS);
685f10c
 
685f10c
 	CONFIRM((void *) n >= base);
685f10c
-	CONFIRM((char *) n - (char *) base <= (int) nodemax);
685f10c
+	CONFIRM((size_t)((char *) n - (char *) base) <= nodemax);
685f10c
 	CONFIRM(DNS_RBTNODE_VALID(n));
685f10c
 
685f10c
 	dns_name_init(&nodename, NULL);
685f10c
@@ -939,7 +939,8 @@ dns_rbt_deserialize_tree(void *base_address, size_t filesize,
685f10c
 	rbt->root = (dns_rbtnode_t *)((char *)base_address +
685f10c
 				header_offset + header->first_node_offset);
685f10c
 
685f10c
-	if ((header->nodecount * sizeof(dns_rbtnode_t)) > filesize) {
685f10c
+	if ((header->nodecount * sizeof(dns_rbtnode_t)) > filesize
685f10c
+	    || header->first_node_offset > filesize) {
685f10c
 		result = ISC_R_INVALIDFILE;
685f10c
 		goto cleanup;
685f10c
 	}
685f10c
-- 
685f10c
2.20.1
685f10c