From 3911e7610f29dc664cbe8336f35c0652cd74652e Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 13 Mar 2014 12:37:07 +1100 Subject: [PATCH] 3785. [bug] Debugging code dumphex didn't accept arbitarily long input (only compiled with -DDEBUG). [RT #35544] --- CHANGES | 3 +++ lib/dns/rbt.c | 27 ++++++++++++++++++--------- lib/dns/rbtdb.c | 23 ++++++++++++++++------- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index b14faa51d3..ca3e7ebe5a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +3785. [bug] Debugging code dumphex didn't accept arbitarily long + input (only compiled with -DDEBUG). [RT #35544] + 3784. [bug] Using "rrset-order fixed" when it had not been enabled at compile time caused inconsistent results. It now works as documented, defaulting diff --git a/lib/dns/rbt.c b/lib/dns/rbt.c index e2f82d83ef..e1421f826d 100644 --- a/lib/dns/rbt.c +++ b/lib/dns/rbt.c @@ -306,16 +306,25 @@ static void printnodename(dns_rbtnode_t *node); static void hexdump(const char *desc, unsigned char *data, size_t size) { - char hexdump[BUFSIZ]; + char hexdump[BUFSIZ * 2 + 1]; isc_buffer_t b; isc_region_t r; + isc_result_t result; + size_t bytes; - isc_buffer_init(&b, hexdump, sizeof(hexdump)); - r.base = data; - r.length = size; - isc_hex_totext(&r, 0, "", &b); - isc_buffer_putuint8(&b, 0); - fprintf(stderr, "%s: %s\n", desc, hexdump); + fprintf(stderr, "%s: ", desc); + do { + isc_buffer_init(&b, hexdump, sizeof(hexdump)); + r.base = data; + r.length = bytes = (size > BUFSIZ) ? BUFSIZ : size; + result = isc_hex_totext(&r, 0, "", &b); + RUNTIME_CHECK(result == ISC_R_SUCCESS); + isc_buffer_putuint8(&b, 0); + fprintf(stderr, "%s", hexdump); + data += bytes; + size -= bytes; + } while (size > 0); + fprintf(stderr, "\n"); } #endif @@ -644,7 +653,7 @@ dns_rbt_serialize_tree(FILE *file, dns_rbt_t *rbt, isc_crc64_final(&crc); #ifdef DEBUG - hexdump("serializing CRC", &crc, sizeof(crc)); + hexdump("serializing CRC", (unsigned char *)&crc, sizeof(crc)); #endif /* Serialize header */ @@ -839,7 +848,7 @@ dns_rbt_deserialize_tree(void *base_address, size_t filesize, isc_crc64_final(&crc); #ifdef DEBUG - hexdump("deserializing CRC", &crc, sizeof(crc)); + hexdump("deserializing CRC", (unsigned char *)&crc, sizeof(crc)); #endif /* Check file hash */ diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c index 0e705fad14..481c7117cd 100644 --- a/lib/dns/rbtdb.c +++ b/lib/dns/rbtdb.c @@ -748,16 +748,25 @@ static unsigned int init_count; #ifdef DEBUG static void hexdump(const char *desc, unsigned char *data, size_t size) { - char hexdump[BUFSIZ]; + char hexdump[BUFSIZ * 2 + 1]; isc_buffer_t b; isc_region_t r; + isc_result_t result; + size_t bytes; - isc_buffer_init(&b, hexdump, sizeof(hexdump)); - r.base = data; - r.length = size; - isc_hex_totext(&r, 0, "", &b); - isc_buffer_putuint8(&b, 0); - fprintf(stderr, "%s: %s\n", desc, hexdump); + fprintf(stderr, "%s: ", desc); + do { + isc_buffer_init(&b, hexdump, sizeof(hexdump)); + r.base = data; + r.length = bytes = (size > BUFSIZ) ? BUFSIZ : size; + result = isc_hex_totext(&r, 0, "", &b); + RUNTIME_CHECK(result == ISC_R_SUCCESS); + isc_buffer_putuint8(&b, 0); + fprintf(stderr, "%s", hexdump); + data += bytes; + size -= bytes; + } while (size > 0); + fprintf(stderr, "\n"); } #endif