Skip to content

Commit 4059c5f

Browse files
committed
Check additional section; allow only OPT and RRSIG
Signed-off-by: Karel Bilek <kb@karelbilek.com>
1 parent a31f019 commit 4059c5f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pdns/dnsparser.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,29 @@ void shuffleDNSPacket(char* packet, size_t length, const dnsheader_aligned& alig
10521052

10531053
indexes.push_back(dpm.getOffset());
10541054

1055+
// also check additional section
1056+
const uint16_t arcount = ntohs(dhp->arcount);
1057+
for(size_t iter = 0; iter < arcount; ++iter) {
1058+
const std::optional<size_t> domain_pointer = dpm.skipDomainName();
1059+
const bool pointer_before_as = domain_pointer.value_or(0) < indexes[0];
1060+
if (!pointer_before_as) {
1061+
// pointers could break by shuffling - bailing out
1062+
return;
1063+
}
1064+
const uint16_t dnstype = dpm.get16BitInt();
1065+
if (!(dnstype == QType::OPT || dnstype == QType::RRSIG)){
1066+
// anything else than OPT - might potentionally have pointers in rdata
1067+
return;
1068+
}
1069+
1070+
/* type and class */
1071+
dpm.skipBytes(2);
1072+
1073+
/* ttl */
1074+
dpm.skipBytes(4);
1075+
dpm.skipRData();
1076+
}
1077+
10551078
if (indexes.size() > 2) {
10561079
using uid = std::uniform_int_distribution<std::vector<uint32_t>::size_type>;
10571080
uid dist;

0 commit comments

Comments
 (0)