From 0be83cf063a9b096487b9a6076d67ee3652a0a9a Mon Sep 17 00:00:00 2001 From: kris Date: Tue, 11 May 2010 03:22:42 +0000 Subject: [PATCH] Move around a few gettimeofday() calls, including where port scan timing comparisons would be affected by debugging level: http://seclists.org/nmap-dev/2010/q2/373 --- CHANGELOG | 4 ++++ scan_engine.cc | 26 ++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f7f27f872..5370d768c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ # Nmap Changelog ($Id$); -*-text-*- +o Fixed where the time variable used in port scanning for comparison + to other times (for probe timeouts, etc) could result in different + behavior based on the debugging level. [Kris] + o Moved the parse_long function from ncat to nbase for better reuse, and used it to simplify netmask parsing code. This patch was contributed by William Pursell. diff --git a/scan_engine.cc b/scan_engine.cc index 37ac1f704..fddca2dd9 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -3575,13 +3575,12 @@ static void doAnyOutstandingRetransmits(UltraScanInfo *USI) { unsigned int maxtries; struct timeval tv_start = {0}; - if (o.debugging) { - gettimeofday(&USI->now, NULL); - tv_start = USI->now; - } gettimeofday(&USI->now, NULL); + if (o.debugging) + tv_start = USI->now; + /* Loop until we get through all the hosts without a retransmit or we're not OK to send any more. */ do { @@ -3634,10 +3633,9 @@ static void doAnyOutstandingRetransmits(UltraScanInfo *USI) { } } while (USI->gstats->sendOK(NULL) && retrans != 0); + gettimeofday(&USI->now, NULL); if (o.debugging) { - long tv_diff; - gettimeofday(&USI->now, NULL); - tv_diff = TIMEVAL_MSEC_SUBTRACT(USI->now, tv_start); + long tv_diff = TIMEVAL_MSEC_SUBTRACT(USI->now, tv_start); if (tv_diff > 30) log_write(LOG_PLAIN, "%s took %lims\n", __func__, tv_diff); } } @@ -4948,11 +4946,12 @@ static void processData(UltraScanInfo *USI) { bool tryno_capped = false, tryno_mayincrease = false; struct timeval tv_start = {0}; - if (o.debugging) { - gettimeofday(&USI->now, NULL); + + gettimeofday(&USI->now, NULL); + + if (o.debugging) tv_start = USI->now; - } - + /* First go through hosts and remove any completed ones from incompleteHosts */ USI->removeCompletedHosts(); if (USI->incompleteHostsEmpty()) @@ -5065,10 +5064,9 @@ static void processData(UltraScanInfo *USI) { } } + gettimeofday(&USI->now, NULL); if (o.debugging) { - long tv_diff; - gettimeofday(&USI->now, NULL); - tv_diff = TIMEVAL_MSEC_SUBTRACT(USI->now, tv_start); + long tv_diff = TIMEVAL_MSEC_SUBTRACT(USI->now, tv_start); if (tv_diff > 30) log_write(LOG_PLAIN, "%s took %lims\n", __func__, tv_diff); } }