From 56fddb46ac58cce03737ef95da29fd687ae7056f Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 19 Mar 2019 16:42:25 +0100 Subject: [PATCH] rec: Handle invalid numeric values from the control channel --- pdns/rec_channel_rec.cc | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 75bdc2e5a0..bb5bfba56b 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -696,8 +696,13 @@ static string setMinimumTTL(T begin, T end) { if(end-begin != 1) return "Need to supply new minimum TTL number\n"; - SyncRes::s_minimumTTL = pdns_stou(*begin); - return "New minimum TTL: " + std::to_string(SyncRes::s_minimumTTL) + "\n"; + try { + SyncRes::s_minimumTTL = pdns_stou(*begin); + return "New minimum TTL: " + std::to_string(SyncRes::s_minimumTTL) + "\n"; + } + catch (const std::exception& e) { + return "Error parsing the new minimum TTL number: " + std::string(e.what()) + "\n"; + } } template @@ -705,8 +710,13 @@ static string setMinimumECSTTL(T begin, T end) { if(end-begin != 1) return "Need to supply new ECS minimum TTL number\n"; - SyncRes::s_minimumECSTTL = pdns_stou(*begin); - return "New minimum ECS TTL: " + std::to_string(SyncRes::s_minimumECSTTL) + "\n"; + try { + SyncRes::s_minimumECSTTL = pdns_stou(*begin); + return "New minimum ECS TTL: " + std::to_string(SyncRes::s_minimumECSTTL) + "\n"; + } + catch (const std::exception& e) { + return "Error parsing the new ECS minimum TTL number: " + std::string(e.what()) + "\n"; + } } template @@ -714,8 +724,13 @@ static string setMaxCacheEntries(T begin, T end) { if(end-begin != 1) return "Need to supply new cache size\n"; - g_maxCacheEntries = pdns_stou(*begin); - return "New max cache entries: " + std::to_string(g_maxCacheEntries) + "\n"; + try { + g_maxCacheEntries = pdns_stou(*begin); + return "New max cache entries: " + std::to_string(g_maxCacheEntries) + "\n"; + } + catch (const std::exception& e) { + return "Error parsing the new cache size: " + std::string(e.what()) + "\n"; + } } template @@ -723,8 +738,13 @@ static string setMaxPacketCacheEntries(T begin, T end) { if(end-begin != 1) return "Need to supply new packet cache size\n"; - g_maxPacketCacheEntries = pdns_stou(*begin); - return "New max packetcache entries: " + std::to_string(g_maxPacketCacheEntries) + "\n"; + try { + g_maxPacketCacheEntries = pdns_stou(*begin); + return "New max packetcache entries: " + std::to_string(g_maxPacketCacheEntries) + "\n"; + } + catch (const std::exception& e) { + return "Error parsing the new packet cache size: " + std::string(e.what()) + "\n"; + } } -- 2.47.2