From 1a2d029efb4dd976f90e3c99b7fbc5a94e4fe197 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Wed, 6 Jan 2021 18:58:00 +0100 Subject: [PATCH] geoipbackend: use const_iterator ==8618==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffd8c5a1420 at pc 0x55bee0a5d899 bp 0x7ffd8c5a0710 sp 0x7ffd8c5a0708 READ of size 1 at 0x7ffd8c5a1420 thread T0 #0 0x55bee0a5d898 in YAML::Node::begin() const /usr/include/yaml-cpp/node/impl.h:284:8 #1 0x55bee0a3f2f0 in GeoIPBackend::initialize() /opt/project/modules/geoipbackend/geoipbackend.cc:163:27 #2 0x55bee0a3d0d3 in GeoIPBackend::GeoIPBackend(std::__cxx11::basic_string, std::allocator > const&) /opt/project/modules/geoipbackend/geoipbackend.cc:86:5 #3 0x55bee0a784eb in GeoIPFactory::make(std::__cxx11::basic_string, std::allocator > const&) /opt/project/modules/geoipbackend/geoipbackend.cc:1008:16 #4 0x55bedff6cb18 in BackendMakerClass::all(bool) /opt/project/pdns/dnsbackend.cc:200:46 #5 0x55bee07d3abe in UeberBackend::UeberBackend(std::__cxx11::basic_string, std::allocator > const&) /opt/project/pdns/ueberbackend.cc:479:28 #6 0x55bee060579c in PacketHandler::PacketHandler() /opt/project/pdns/packethandler.cc:65:32 #7 0x55bedfee1748 in std::unique_ptr > make_unique() /opt/project/pdns/./misc.hh:571:35 #8 0x55bee079376d in TCPNameserver::go() /opt/project/pdns/tcpreceiver.cc:85:9 #9 0x55bedfecf7b7 in mainthread() /opt/project/pdns/common_startup.cc:656:7 #10 0x55bee0655f67 in main /opt/project/pdns/receiver.cc:654:5 #11 0x7f374b4b809a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a) #12 0x55bedfc9a989 in _start (/opt/pdns-auth/sbin/pdns_server+0x2736989) Address 0x7ffd8c5a1420 is located in stack of thread T0 at offset 3040 in frame #0 0x55bee0a3d5ef in GeoIPBackend::initialize() /opt/project/modules/geoipbackend/geoipbackend.cc:115 --- modules/geoipbackend/geoipbackend.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/geoipbackend/geoipbackend.cc b/modules/geoipbackend/geoipbackend.cc index 5aaa06b47a1e..d52ad031c8e0 100644 --- a/modules/geoipbackend/geoipbackend.cc +++ b/modules/geoipbackend/geoipbackend.cc @@ -150,7 +150,8 @@ void GeoIPBackend::initialize() { global_custom_mapping = mapping.as>(); } - for(YAML::Node domain : config["domains"]) { + for(YAML::const_iterator _domain = config["domains"].begin(); _domain != config["domains"].end(); _domain++) { + const auto& domain = *_domain; GeoIPDomain dom; dom.id = tmp_domains.size(); dom.domain = DNSName(domain["domain"].as()); @@ -160,8 +161,8 @@ void GeoIPBackend::initialize() { DNSName qname = DNSName(recs->first.as()); vector rrs; - for(YAML::Node item : recs->second) { - YAML::const_iterator rec = item.begin(); + for(YAML::const_iterator item = recs->second.begin(); item != recs->second.end(); item++) { + YAML::const_iterator rec = item->begin(); GeoIPDNSResourceRecord rr; rr.domain_id = dom.id; rr.ttl = dom.ttl;