From 45533e5972d457693509507de425cd62ab2986ec Mon Sep 17 00:00:00 2001 From: david Date: Mon, 7 Sep 2009 22:04:10 +0000 Subject: [PATCH] Don't dereference a null pointer when printing out a traceroute error message. The dereferencing could not actually happen because it would only happen with a trace of zero hops with no probes sent, and in that case we skip the traceroute entirely. Patch by Ankur Nandwani. --- traceroute.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/traceroute.cc b/traceroute.cc index d7c4d6b22..8740777fb 100644 --- a/traceroute.cc +++ b/traceroute.cc @@ -1012,10 +1012,12 @@ Traceroute::outputTarget(Target * t) { } log_write(LOG_PLAIN, "%s", Tbl->printableTable(NULL)); - if (tg->getState() == G_DEAD_TTL) + if (tg->getState() == G_DEAD_TTL) { log_write(LOG_PLAIN, "! maximum TTL reached (50)\n"); - else if (!tg->gotReply || (tp && (tp->ipreplysrc.s_addr != tg->ipdst))) - log_write(LOG_PLAIN, "! destination not reached (%s)\n", inet_ntoa(tp->ipdst)); + } else if (!tg->gotReply || (tp && (tp->ipreplysrc.s_addr != tg->ipdst))) { + struct in_addr addr = { tg->ipdst }; + log_write(LOG_PLAIN, "! destination not reached (%s)\n", inet_ntoa(addr)); + } log_flush(LOG_PLAIN); delete Tbl; @@ -1082,8 +1084,10 @@ Traceroute::outputXMLTrace(TraceGroup * tg) { if (tg->getState() == G_DEAD_TTL) log_write(LOG_XML, "\n"); - else if (!tg->gotReply || (tp && (tp->ipreplysrc.s_addr != tg->ipdst))) - log_write(LOG_XML, "\n", inet_ntoa(tp->ipdst)); + else if (!tg->gotReply || (tp && (tp->ipreplysrc.s_addr != tg->ipdst))) { + addr.s_addr = tg->ipdst; + log_write(LOG_XML, "\n", inet_ntoa(addr)); + } /* traceroute XML footer */ log_write(LOG_XML, "\n");