]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Avoid overflow when computing latency
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 28 Feb 2020 12:46:03 +0000 (13:46 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 16 Dec 2020 11:13:46 +0000 (12:13 +0100)
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)

(cherry picked from commit b7d61cb18a9bc99d2c759f24e1340efc7a1c7725)

pdns/pdns_recursor.cc

index 9f484a7ec02a6ab8b6504676fbd0687a102a11e6..0f27ebe977ee48e2e02c1a07202a6b274ee47b6d 100644 (file)
@@ -2137,7 +2137,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