From c80bc2efb27995d4a19537909c90e067551b2fbc Mon Sep 17 00:00:00 2001 From: dmiller Date: Thu, 16 May 2024 19:31:47 +0000 Subject: [PATCH] Rate-limit capacity scale-downs to 1 per MIN_DNS_TIMEOUT --- nmap_dns.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/nmap_dns.cc b/nmap_dns.cc index 85a5c9072..b8728f7d0 100644 --- a/nmap_dns.cc +++ b/nmap_dns.cc @@ -556,7 +556,7 @@ static int deal_with_timedout_reads(bool adjust_timing) { if (nextI == servI->in_process.end()) continue; struct timeval earliest_sent = now; - bool adjusted = false; + bool adjusted = !adjust_timing; bool may_increase = adjust_timing; do { reqI = nextI++; @@ -1195,7 +1195,7 @@ static void nmap_mass_dns_core(DNS::Request *requests, int num_requests) { std::list::iterator reqI; request *tpreq; - int timeout; + int timeout = 0; int i; char spmobuf[1024]; @@ -1280,8 +1280,16 @@ static void nmap_mass_dns_core(DNS::Request *requests, int num_requests) { SPM = new ScanProgressMeter(spmobuf); stat_actual = total_reqs; + int since_last = 0; while (total_reqs > 0) { - timeout = deal_with_timedout_reads(true); + since_last += timeout; + if (since_last > MIN_DNS_TIMEOUT) { + since_last = 0; + timeout = deal_with_timedout_reads(true); + } + else { + timeout = deal_with_timedout_reads(false); + } do_possible_writes();