Skip to content

Commit

Permalink
[ch2833] Detect infinte loop in dealing with DNS name compression.
Browse files Browse the repository at this point in the history
  • Loading branch information
cybermaggedon committed Feb 22, 2018
1 parent fe70ad1 commit 223dec8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/dns_protocol.C
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ void dns_decoder::parse_name(pdu_iter ms, pdu_iter me,
pdu_iter& pos, pdu_iter e, std::string& name,
bool& first)
{

// Save this for later.
pdu_iter start = pos;

validate_iter(pos, e);

while (1) {
Expand All @@ -56,6 +60,11 @@ void dns_decoder::parse_name(pdu_iter ms, pdu_iter me,

pdu_iter pos2 = ms + offset;

// No point calling myself with the same args, that would be
// infinite loop.
if (pos2 == start)
throw std::runtime_error("Infinite loop in DNS structure.");

parse_name(ms, me, pos2, me, name, first);
return;

Expand All @@ -75,6 +84,7 @@ void dns_decoder::parse_name(pdu_iter ms, pdu_iter me,

void dns_decoder::parse()
{

queries.clear();

parse_header(s);
Expand Down

0 comments on commit 223dec8

Please sign in to comment.