]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
dig with IDN output could leak memory on ISC_R_NOSPACE retry 12462/head
authorMark Andrews <marka@isc.org>
Tue, 28 Jul 2026 06:23:24 +0000 (16:23 +1000)
committerMark Andrews <marka@isc.org>
Thu, 30 Jul 2026 20:42:48 +0000 (06:42 +1000)
The IDN to text display call back could leak the memory holding the
converted name if it did not fit into the buffer.  This has been fixed.

bin/dig/dighost.c

index cdc925e6c8ed9f979f425ffaa491e33c7e02213b..6bb349dbc02f47fb60758452d0525190d4cac6b1 100644 (file)
@@ -4703,6 +4703,7 @@ idn_filter(isc_buffer_t *buffer, unsigned int start) {
        char *dst = NULL;
        size_t srclen, dstlen;
        int res;
+       isc_result_t result;
 
        /*
         * Copy name from 'buffer' to 'src' and terminate it with NULL.
@@ -4722,7 +4723,7 @@ idn_filter(isc_buffer_t *buffer, unsigned int start) {
        }
        resetlocale(LC_ALL);
        if (res != IDN2_OK) {
-               return ISC_R_SUCCESS;
+               CLEANUP(ISC_R_SUCCESS);
        }
 
        /*
@@ -4730,14 +4731,18 @@ idn_filter(isc_buffer_t *buffer, unsigned int start) {
         */
        dstlen = strlen(dst);
        if (isc_buffer_length(buffer) < start + dstlen) {
-               return ISC_R_NOSPACE;
+               CLEANUP(ISC_R_NOSPACE);
        }
        isc_buffer_subtract(buffer, srclen);
        memmove(isc_buffer_used(buffer), dst, dstlen);
        isc_buffer_add(buffer, dstlen);
 
-       idn2_free(dst);
-       return ISC_R_SUCCESS;
+       result = ISC_R_SUCCESS;
+cleanup:
+       if (dst != NULL) {
+               idn2_free(dst);
+       }
+       return result;
 }
 
 /*%