Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth LUA createForward6: on parse problem, return :: instead of SERVFAIL #14630

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions pdns/lua-record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -966,21 +966,22 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
lua.writeFunction("createForward6", []() {
DNSName rel=s_lua_record_ctx->qname.makeRelative(s_lua_record_ctx->zone);
auto parts = rel.getRawLabels();
string address = "::";

if(parts.size()==8) {
string tot;
for(int i=0; i<8; ++i) {
if(i)
if(i != 0) {
tot.append(1,':');
}
tot+=parts[i];
}
ComboAddress ca(tot);
return ca.toString();
address = tot;
}
else if(parts.size()==1) {
if (parts[0].find('-') != std::string::npos) {
boost::replace_all(parts[0],"-",":");
ComboAddress ca(parts[0]);
return ca.toString();
address = parts[0];
} else {
if (parts[0].size() >= 32) {
auto ippart = parts[0].substr(parts[0].size()-32);
Expand All @@ -994,13 +995,20 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
ippart.substr(24, 4) + ":" +
ippart.substr(28, 4);

ComboAddress ca(fulladdress);
return ca.toString();
address = fulladdress;
}
}
}

return std::string("::");
try {
ComboAddress caddress(address);
address = caddress.toString();
}
catch (PDNSException &error) {
address = "::";
}

return address;
});
lua.writeFunction("createReverse6", [](string format, boost::optional<std::unordered_map<string,string>> e){
vector<ComboAddress> candidates;
Expand Down
12 changes: 11 additions & 1 deletion regression-tests.auth-py/test_LuaRecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ class TestLuaRecords(AuthTest):
createforward6.example.org. 3600 IN NS ns1.example.org.
createforward6.example.org. 3600 IN NS ns2.example.org.
* IN LUA AAAA "filterForward(createForward6(), newNMG{{'2000::/3'}}, 'fe80::1')"
""",
'createforward6-nofilter.example.org': """
createforward6-nofilter.example.org. 3600 IN SOA {soa}
createforward6-nofilter.example.org. 3600 IN NS ns1.example.org.
createforward6-nofilter.example.org. 3600 IN NS ns2.example.org.
* IN LUA AAAA "createForward6(), newNMG{{'2000::/3'}}"
"""
# the separate createforward6 zone is because some of the code in lua-record.cc insists on working relatively to the zone apex
# the separate createforward6 zones are because some of the code in lua-record.cc insists on working relatively to the zone apex
}
_web_rrsets = []

Expand Down Expand Up @@ -1027,6 +1033,10 @@ def testCreateForwardAndReverse(self):
"blabla20010002000300040005000600070db8" : "2001:2:3:4:5:6:7:db8",
"4000-db8--1" : "fe80::1" # filtered, with fallback address override
}),
".createforward6-nofilter.example.org." : (dns.rdatatype.AAAA, {
"foo" : "::",
"averylongstringthatismorethan32chars" : "::"
}),
".createreverse6.example.org." : (dns.rdatatype.PTR, {
"8.b.d.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.2" : "2001--db8.example.com.",
"1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2" : "example.example.com." # exception
Expand Down
Loading