Skip to content

Commit

Permalink
Ensure a valid range to string() in PacketReader::getUnquotedText()
Browse files Browse the repository at this point in the history
In some cases we might have called:

string::string(InputIt first, InputIt last)

with last < first, which is invalid.

libstdc++ handles that gracefully by throwing an out-of-range exception
but libc++ tries to allocate a negative value of bytes, which in turns
triggers a request for a very large memory allocation, which fails.
  • Loading branch information
rgacogne committed May 14, 2019
1 parent 9b8a3ae commit d7bbbcf
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pdns/dnsparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ string PacketReader::getUnquotedText(bool lenField)
else
stop_at = d_recordlen;

/* think unsigned overflow */
if (stop_at < d_pos) {
throw std::out_of_range("getUnquotedText out of record range");
}

if(stop_at == d_pos)
return "";

Expand Down

0 comments on commit d7bbbcf

Please sign in to comment.