From 0ffa072a6bef20b494e84874ade8f96c180ed804 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 20 Aug 2009 19:52:17 +0000 Subject: [PATCH] Fix an off-by-one error in traceroute consolidation. In debugging mode, the list of consolidated hops (the ones that match the reference trace) was printed out one hop further than it should have been. So if a trace diverged from the reference trace at the sixth hop, it would print out the first six hops of the reference trace when it should have done only five. This extra row, as well as being incorrect, could cause an assertion failure by making the output table one row bigger than its preallocated capacity. --- traceroute.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/traceroute.cc b/traceroute.cc index 07981aeb8..0d76bad1a 100644 --- a/traceroute.cc +++ b/traceroute.cc @@ -901,9 +901,7 @@ Traceroute::outputTarget(Target * t) { this->outputXMLTrace(tg); /* table headers */ - /* This should be tg->hopDistance + 1, but there is a bug that sometimes - causes an extra row to be printed. */ - Tbl = new NmapOutputTable(tg->hopDistance+2, 3); + Tbl = new NmapOutputTable(tg->hopDistance+1, 3); Tbl->addItem(row_count, HOP_COL, false, "HOP", 3); Tbl->addItem(row_count, RTT_COL, false, "RTT", 3); Tbl->addItem(row_count, HOST_COL, false, "ADDRESS", 7); @@ -913,7 +911,7 @@ Traceroute::outputTarget(Target * t) { assert(row_count <= tg->hopDistance); /* consolidate hops based on the reference trace (commonPath) */ - if (commonPath[ttl_count] && ttl_count <= tg->consolidation_start) { + if (commonPath[ttl_count] && ttl_count < tg->consolidation_start) { /* do not consolidate in debug mode */ if (o.debugging) { row_count++;