From c98ac1d9d5d2cb00d2ec7fb5a858d209d6bf6cf6 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 28 Feb 2020 13:46:03 +0100 Subject: [PATCH] rec: Avoid overflow when computing latency Reported by UBSan: [2020-02-28 12:21:21] pdns_recursor.cc:1841:31: runtime error: -276679 is outside the range of representable values of type 'unsigned long' [2020-02-28 12:21:21] #0 0x5610bb76af48 in startDoResolve(void*) /home/travis/build/rgacogne/pdns/pdns/recursordist/pdns-recursor-0.0.0.0.HEAD.g5d6e6b9f95.dirty/pdns_recursor.cc:1841:31 [2020-02-28 12:21:21] #1 0x5610bb7d60ac in MTasker::makeThread(void (*)(void*), void*)::{lambda()#1}::operator()() const /home/travis/build/rgacogne/pdns/pdns/recursordist/pdns-recursor-0.0.0.0.HEAD.g5d6e6b9f95.dirty/./mtasker.cc:284:7 [2020-02-28 12:21:21] #2 0x5610bb6bae9d in boost::function0::operator()() const /usr/include/boost/function/function_template.hpp:766:14 [2020-02-28 12:21:21] #3 0x5610bb6ba21b in threadWrapper(long) /home/travis/build/rgacogne/pdns/pdns/recursordist/pdns-recursor-0.0.0.0.HEAD.g5d6e6b9f95.dirty/./mtasker_fcontext.cc:144:9 [2020-02-28 12:21:21] #4 0x7f29cb06d70d in make_fcontext (/usr/lib/x86_64-linux-gnu/libboost_context.so.1.54.0+0x70d) --- pdns/pdns_recursor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 06d3c509c09c9..718e97e6046e4 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1838,7 +1838,7 @@ static void startDoResolve(void *p) else g_stats.answersSlow++; - uint64_t newLat=(uint64_t)(spent*1000000); + uint64_t newLat=(uint64_t)(spent*static_cast(1000000)); newLat = min(newLat,(uint64_t)(((uint64_t) g_networkTimeoutMsec)*1000)); // outliers of several minutes exist.. g_stats.avgLatencyUsec=(1-1.0/g_latencyStatSize)*g_stats.avgLatencyUsec + (float)newLat/g_latencyStatSize; // no worries, we do this for packet cache hits elsewhere