Skip to content

Commit

Permalink
rec: Avoid overflow when computing latency
Browse files Browse the repository at this point in the history
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<PacketID, std::string>::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<void>::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)
  • Loading branch information
rgacogne committed Feb 28, 2020
1 parent a818163 commit b7d61cb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pdns/pdns_recursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(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
Expand Down

0 comments on commit b7d61cb

Please sign in to comment.