File 0001-Fix-heap-overflow-problem-thanks-to-david-keeler-bug-.diff of Package ldns

From 165419ce11cc217657251ae1a3388daa6b51ee2c Mon Sep 17 00:00:00 2001
From: willem <willem@af62348d-a3ea-0310-b058-bb613a78d823>
Date: Wed, 24 Aug 2011 20:04:48 +0000
Subject: [PATCH] Fix heap overflow problem thanks to david keeler: bug #403

git-svn-id: http://www.nlnetlabs.nl/svn/ldns/trunk@3527 af62348d-a3ea-0310-b058-bb613a78d823
---
 rr.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

Index: ldns-1.5.1/rr.c
===================================================================
--- ldns-1.5.1.orig/rr.c
+++ ldns-1.5.1/rr.c
@@ -419,7 +419,10 @@ ldns_rr_new_frm_str_internal(ldns_rr **n
 						cur_hex_data_size = 0;
 						while(cur_hex_data_size < 2 * hex_data_size) {
 							c = ldns_bget_token(rd_buf, rd, delimiters, LDNS_MAX_RDFLEN);
-							if (c == -1) {
+							if (c != -1) {
+								rd_strlen = strlen(rd);
+							}
+							if (c == -1 || cur_hex_data_size + rd_strlen > 2 * hex_data_size) {
 								LDNS_FREE(hex_data_str);
 								LDNS_FREE(rd);
 								LDNS_FREE(b64);
@@ -429,7 +432,6 @@ ldns_rr_new_frm_str_internal(ldns_rr **n
 								ldns_rr_free(new);
 								return LDNS_STATUS_SYNTAX_RDATA_ERR;
 							}
- 							rd_strlen = strlen(rd);
 							rd_strlen = strlen(rd);
 							strncpy(hex_data_str + cur_hex_data_size, rd, rd_strlen);
 							cur_hex_data_size += rd_strlen;