]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
report execution failure in wildcard LUA records
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Tue, 12 Jun 2018 14:33:44 +0000 (16:33 +0200)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Wed, 31 Oct 2018 14:03:02 +0000 (15:03 +0100)
pdns/lua-record.cc
pdns/packethandler.cc
regression-tests.auth-py/test_LuaRecords.py

index 60374202aac361e3791a599e4991d6ddaf8cdd1d..ad070e8a9fa6a2d77895817b6194f5ba8ceb6bbc 100644 (file)
@@ -450,11 +450,7 @@ static vector<pair<int, ComboAddress> > convWIplist(std::unordered_map<int, wipl
 
 std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, const DNSName& query, const DNSName& zone, int zoneid, const DNSPacket& dnsp, uint16_t qtype)
 {
-  //  cerr<<"Called for "<<query<<", in zone "<<zone<<" for type "<<qtype<<endl;
-  //  cerr<<"Code: '"<<code<<"'"<<endl;
-
   AuthLua4 alua;
-  //
 
   std::vector<shared_ptr<DNSRecordContent>> ret;
 
@@ -491,13 +487,14 @@ std::vector<shared_ptr<DNSRecordContent>> luaSynth(const std::string& code, cons
 
   lua.writeFunction("closestMagic", [&bestwho,&query]() {
       vector<ComboAddress> candidates;
+      // Getting something like 192-0-2-1.192-0-2-2.198-51-100-1.example.org
       for(auto l : query.getRawLabels()) {
         boost::replace_all(l, "-", ".");
         try {
           candidates.emplace_back(l);
         } catch (const PDNSException& e) {
-          // we want the reason to be reported by the lua wrapper
-          throw std::invalid_argument(e.reason);
+          // no need to continue as we most likely reached the end of the ip list
+          break ;
         }
       }
       return pickclosest(bestwho, candidates).toString();
index 6fa2a7be292d335fdf8368510d81cd1bf40c4d50..5d13d70d02a4fba9cd7a9b8cdac5ddbe7be80d60 100644 (file)
@@ -386,17 +386,12 @@ bool PacketHandler::getBestWildcard(DNSPacket *p, SOAData& sd, const DNSName &ta
         if(rec->d_type == QType::CNAME || rec->d_type == p->qtype.getCode()) {
           //    noCache=true;
           DLOG(g_log<<"Executing Lua: '"<<rec->getCode()<<"'"<<endl);
-          try {
-            auto recvec=luaSynth(rec->getCode(), target, sd.qname, sd.domain_id, *p, rec->d_type);
-            for(const auto& r : recvec) {
-              rr.dr.d_type = rec->d_type; // might be CNAME
-              rr.dr.d_content = r;
-              rr.scopeMask = p->getRealRemote().getBits(); // this makes sure answer is a specific as your question
-              ret->push_back(rr);
-            }
-          }
-          catch(std::exception &e) {
-            ;
+          auto recvec=luaSynth(rec->getCode(), target, sd.qname, sd.domain_id, *p, rec->d_type);
+          for(const auto& r : recvec) {
+            rr.dr.d_type = rec->d_type; // might be CNAME
+            rr.dr.d_content = r;
+            rr.scopeMask = p->getRealRemote().getBits(); // this makes sure answer is a specific as your question
+            ret->push_back(rr);
           }
         }
       }
index f812b479e8f66c9f7e920274f4eec4d374914f69..15533ad133da33c53786ec5d46d0e28c711058f1 100644 (file)
@@ -337,6 +337,16 @@ www-balanced     IN           CNAME 1-1-1-3.17-1-2-4.1-2-3-5.magic.example.org.
         self.assertRcodeEqual(res, dns.rcode.NOERROR)
         self.assertRRsetInAnswer(res, expected)
 
+    def testWildcardError(self):
+        """
+        Ensure errors coming from LUA wildcards are reported
+        """
+        query = dns.message.make_query('failure.magic.example.org', 'A')
+
+        res = self.sendUDPQuery(query)
+        self.assertRcodeEqual(res, dns.rcode.SERVFAIL)
+        self.assertAnswerEmpty(res)
+
     def testClosestMagic(self):
         """
         Basic closestMagic() test
@@ -488,8 +498,6 @@ www-balanced     IN           CNAME 1-1-1-3.17-1-2-4.1-2-3-5.magic.example.org.
         """
         view() test where no netmask match
         """
-        expected = dns.rrset.from_text('none.view.example.org.', 0,
-                                       dns.rdataclass.IN, 'A')
         query = dns.message.make_query('none.view.example.org', 'A')
 
         res = self.sendUDPQuery(query)