From: Ondřej Surý Date: Fri, 1 Mar 2024 07:26:07 +0000 (+0100) Subject: Add a limit to the number of RRs in RRSets X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9b5485b22c364fb88c27aa04bad4c8f616da3fa;p=thirdparty%2Fbind9.git Add a limit to the number of RRs in RRSets 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= (cherry picked from commit c5c4d00c38530390c9e1ae4c98b65fbbadfe9e5e) (cherry picked from commit 7f705778af729ada7fec36ac4b456c73329bd996) --- diff --git a/configure b/configure index e46858dcf9b..76de61f49a7 100755 --- 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 diff --git a/configure.ac b/configure.ac index cc1c0880d28..be37b9f6313 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/lib/dns/rdataslab.c b/lib/dns/rdataslab.c index b0f77b1972b..347b7d2ce86 100644 --- a/lib/dns/rdataslab.c +++ b/lib/dns/rdataslab.c @@ -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