]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add a limit to the number of RRs in RRSets
authorOndřej Surý <ondrej@isc.org>
Fri, 1 Mar 2024 07:26:07 +0000 (08:26 +0100)
committerOndřej Surý <ondrej@isc.org>
Wed, 5 Jun 2024 07:02:14 +0000 (09:02 +0200)
Previously, the number of RRs in the RRSets were internally unlimited.
As the data structure that holds the RRs is just a linked list, and
there are places where we just walk through all of the RRs, adding an
RRSet with huge number of RRs inside would slow down processing of said
RRSets.

The fix for end-of-life branches make the limit compile-time only for
simplicity and the limit can be changed at the compile time by adding
following define to CFLAGS:

    -DDNS_RDATASET_MAX_RECORDS=<limit>

(cherry picked from commit c5c4d00c38530390c9e1ae4c98b65fbbadfe9e5e)
(cherry picked from commit 7f705778af729ada7fec36ac4b456c73329bd996)

configure
configure.ac
lib/dns/rdataslab.c

index e46858dcf9bc04456ac2c5093cde4d195fa1c96d..76de61f49a775b5e1e9fb8850c0093f7e486d9d6 100755 (executable)
--- a/configure
+++ b/configure
@@ -12185,7 +12185,7 @@ fi
 XTARGETS=
 case "$enable_developer" in
 yes)
-       STD_CDEFINES="$STD_CDEFINES -DISC_LIST_CHECKINIT=1"
+       STD_CDEFINES="$STD_CDEFINES -DISC_LIST_CHECKINIT=1 -DDNS_RDATASET_MAX_RECORDS=5000"
        test "${enable_fixed_rrset+set}" = set || enable_fixed_rrset=yes
        test "${enable_querytrace+set}" = set || enable_querytrace=yes
        test "${enable_filter_aaaa+set}" = set || enable_filter_aaaa=yes
index cc1c0880d285d896c50f0d9be4b3aa4f76361a19..be37b9f6313a836dcf8641639ff2ee1831c44d4b 100644 (file)
@@ -100,7 +100,7 @@ AC_ARG_ENABLE(developer,
 XTARGETS=
 case "$enable_developer" in
 yes)
-       STD_CDEFINES="$STD_CDEFINES -DISC_LIST_CHECKINIT=1"
+       STD_CDEFINES="$STD_CDEFINES -DISC_LIST_CHECKINIT=1 -DDNS_RDATASET_MAX_RECORDS=5000"
        test "${enable_fixed_rrset+set}" = set || enable_fixed_rrset=yes
        test "${enable_querytrace+set}" = set || enable_querytrace=yes
        test "${enable_filter_aaaa+set}" = set || enable_filter_aaaa=yes
index b0f77b1972bfda75d19de452f0dad995582764d3..347b7d2ce86b32b37db78aba3a71580e12096b70 100644 (file)
@@ -115,6 +115,10 @@ fillin_offsets(unsigned char *offsetbase, unsigned int *offsettable,
 }
 #endif
 
+#ifndef DNS_RDATASET_MAX_RECORDS
+#define DNS_RDATASET_MAX_RECORDS 100
+#endif /* DNS_RDATASET_MAX_RECORDS */
+
 isc_result_t
 dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
                           isc_region_t *region, unsigned int reservelen)
@@ -161,6 +165,10 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
                return (ISC_R_SUCCESS);
        }
 
+       if (nitems > DNS_RDATASET_MAX_RECORDS) {
+               return (DNS_R_TOOMANYRECORDS);
+       }
+
        if (nitems > 0xffff)
                return (ISC_R_NOSPACE);
 
@@ -654,6 +662,10 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab,
 #endif
        INSIST(ocount > 0 && ncount > 0);
 
+       if (ocount + ncount > DNS_RDATASET_MAX_RECORDS) {
+               return (DNS_R_TOOMANYRECORDS);
+       }
+
 #if DNS_RDATASET_FIXED
        oncount = ncount;
 #endif