From: Wouter Wijngaards Date: Mon, 8 Oct 2012 10:24:50 +0000 (+0000) Subject: - update ldns-testpkts.c to ldns 1.6.14 version. X-Git-Tag: release-1.4.19rc1~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9aaff22d88741100ef1713dbcc8ca2eb937fb3f4;p=thirdparty%2Funbound.git - update ldns-testpkts.c to ldns 1.6.14 version. git-svn-id: file:///svn/unbound/trunk@2774 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index 9985274b1..5170822f0 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +8 October 2012: Wouter + - update ldns-testpkts.c to ldns 1.6.14 version. + 5 October 2012: Wouter - fix build of pythonmod in objdir (thanks Jakob Schlyter). diff --git a/testcode/ldns-testpkts.c b/testcode/ldns-testpkts.c index d8139511a..7a6c020e8 100644 --- a/testcode/ldns-testpkts.c +++ b/testcode/ldns-testpkts.c @@ -323,7 +323,7 @@ data_buffer2wire(ldns_buffer *data_buffer) uint8_t *hexbuf; int hexbufpos = 0; size_t wirelen; - uint8_t *data_wire = (uint8_t *) ldns_buffer_export(data_buffer); + uint8_t *data_wire = (uint8_t *) ldns_buffer_begin(data_buffer); uint8_t *wire = LDNS_XMALLOC(uint8_t, LDNS_MAX_PACKETLEN); hexbuf = LDNS_XMALLOC(uint8_t, LDNS_MAX_PACKETLEN); @@ -340,6 +340,12 @@ data_buffer2wire(ldns_buffer *data_buffer) (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ) { + if (hexbufpos >= LDNS_MAX_PACKETLEN) { + error("buffer overflow"); + LDNS_FREE(hexbuf); + return 0; + + } hexbuf[hexbufpos] = (uint8_t) c; hexbufpos++; } else if (c == ';') { @@ -354,14 +360,14 @@ data_buffer2wire(ldns_buffer *data_buffer) } break; case 2: + if (hexbufpos >= LDNS_MAX_PACKETLEN) { + error("buffer overflow"); + LDNS_FREE(hexbuf); + return 0; + } hexbuf[hexbufpos] = (uint8_t) c; hexbufpos++; break; - default: - error("unknown state while reading"); - LDNS_FREE(hexbuf); - return 0; - break; } } @@ -371,6 +377,11 @@ data_buffer2wire(ldns_buffer *data_buffer) /* lenient mode: length must be multiple of 2 */ if (hexbufpos % 2 != 0) { + if (hexbufpos >= LDNS_MAX_PACKETLEN) { + error("buffer overflow"); + LDNS_FREE(hexbuf); + return 0; + } hexbuf[hexbufpos] = (uint8_t) '0'; hexbufpos++; } @@ -485,7 +496,10 @@ read_entry(FILE* in, const char* name, int *lineno, uint32_t* default_ttl, reading_hex = false; cur_reply->reply_from_hex = data_buffer2wire(hex_data_buffer); ldns_buffer_free(hex_data_buffer); + hex_data_buffer = NULL; } else if(str_keyword(&parse, "ENTRY_END")) { + if (hex_data_buffer) + ldns_buffer_free(hex_data_buffer); return current; } else if(reading_hex) { ldns_buffer_printf(hex_data_buffer, line); @@ -815,7 +829,7 @@ handle_query(uint8_t* inbuf, ssize_t inlen, struct entry* entries, int* count, /* still try to adjust ID */ answer_size = ldns_buffer_capacity(p->reply_from_hex); outbuf = LDNS_XMALLOC(uint8_t, answer_size); - memcpy(outbuf, ldns_buffer_export(p->reply_from_hex), answer_size); + memcpy(outbuf, ldns_buffer_begin(p->reply_from_hex), answer_size); if(entry->copy_id) { ldns_write_uint16(outbuf, ldns_pkt_id(query_pkt));