]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Reserve 2 * LDNS_MAX_PACKETLEN for hex packets master
authorWillem Toorop <willem@nlnetlabs.nl>
Fri, 5 Jun 2026 09:33:41 +0000 (11:33 +0200)
committerWillem Toorop <willem@nlnetlabs.nl>
Fri, 5 Jun 2026 09:33:41 +0000 (11:33 +0200)
With ldns-testns

Changelog
examples/ldns-testpkts.c

index 74e2631af72dd0bd8f2e613dd6f901c786b85287..7fcda0be022109ab61d6d905399bbae64537c225 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,7 @@
+1.9.?  2026-??-??
+       * Bugfix: ldns-testns needs twice LDNS_MAX_PACKETLEN for the
+         hexadecimal representation of a packet
+
 1.9.0  2025-12-04
        * PR #246: Make ldns_calc_keytag() available for CDNSKEY RR
          Thanks tgreenx and pnax
index c74f0f75477f50b2485fb138cd5c2621f830edc5..c6d54cfb849fc6d275ea8c99e7a998e90b243375 100644 (file)
@@ -340,7 +340,7 @@ data_buffer2wire(ldns_buffer *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);
+       hexbuf = LDNS_XMALLOC(uint8_t, 2*LDNS_MAX_PACKETLEN);
        for (data_buf_pos = 0; data_buf_pos < ldns_buffer_position(data_buffer); data_buf_pos++) {
                c = (int) data_wire[data_buf_pos];
 
@@ -354,7 +354,7 @@ data_buffer2wire(ldns_buffer *data_buffer)
                                        (c >= 'a' && c <= 'f') ||
                                        (c >= 'A' && c <= 'F') )
                                {
-                                       if (hexbufpos >= LDNS_MAX_PACKETLEN) {
+                                       if (hexbufpos >= 2*LDNS_MAX_PACKETLEN) {
                                                error("buffer overflow");
                                                LDNS_FREE(hexbuf);
                                                return 0;
@@ -374,7 +374,7 @@ data_buffer2wire(ldns_buffer *data_buffer)
                                }
                                break;
                        case 2:
-                               if (hexbufpos >= LDNS_MAX_PACKETLEN) {
+                               if (hexbufpos >= 2*LDNS_MAX_PACKETLEN) {
                                        error("buffer overflow");
                                        LDNS_FREE(hexbuf);
                                        return 0;
@@ -385,13 +385,13 @@ data_buffer2wire(ldns_buffer *data_buffer)
                }
        }
 
-       if (hexbufpos >= LDNS_MAX_PACKETLEN) {
+       if (hexbufpos >= 2*LDNS_MAX_PACKETLEN) {
                /*verbose("packet size reached\n");*/
        }
        
        /* lenient mode: length must be multiple of 2 */
        if (hexbufpos % 2 != 0) {
-               if (hexbufpos >= LDNS_MAX_PACKETLEN) {
+               if (hexbufpos >= 2*LDNS_MAX_PACKETLEN) {
                        error("buffer overflow");
                        LDNS_FREE(hexbuf);
                        return 0;