]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
2nd arg to memcpy may be NULL if size is 0
authorWillem Toorop <willem@nlnetlabs.nl>
Sun, 21 Dec 2025 14:32:09 +0000 (15:32 +0100)
committerWillem Toorop <willem@nlnetlabs.nl>
Sun, 21 Dec 2025 14:32:09 +0000 (15:32 +0100)
Found with ldns_native2rdf_int16_data(0, NULL) being called from ldns_pkt_tsig_sign_next()

Changelog
rdata.c

index a44ac76ec12a92ada180a9867030273093c62f6a..6106b66ba936600b1bee15390ad052b977a08403 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,8 @@
        * Fix #290: ldns-verify-zone prints to stdout instead of myerr
          Thanks RoyArends
        * Fix memory leak in ldns-notify
+       * Prevent "null pointer pass as 2nd argument to memcpy" runtime
+         error, when size is 0
        
 1.9.0  2025-12-04
        * PR #246: Make ldns_calc_keytag() available for CDNSKEY RR
diff --git a/rdata.c b/rdata.c
index 5befc9e70f72172e2d1774e97f23659443600e2b..429d109e982819af54ad6dc93dd9901ed0d19def 100644 (file)
--- a/rdata.c
+++ b/rdata.c
@@ -167,7 +167,9 @@ ldns_native2rdf_int16_data(size_t size, uint8_t *data)
                return NULL;
        }
        ldns_write_uint16(rdf_data, size);
-       memcpy(rdf_data + 2, data, size);
+       if (size) {
+               memcpy(rdf_data + 2, data, size);
+       }
        rdf = ldns_rdf_new(LDNS_RDF_TYPE_INT16_DATA, size + 2, rdf_data);
         if(!rdf)
                 LDNS_FREE(rdf_data);