]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Ensure a valid range to string() in PacketReader::getUnquotedText() 7813/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 10 May 2019 16:04:38 +0000 (18:04 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 14 May 2019 12:21:26 +0000 (14:21 +0200)
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.

pdns/dnsparser.cc

index 233258a3efb57fcafb3a448638013ec11c03b4dc..f89ff3f67a003b77c016000620c4aab5b4bcb9fb 100644 (file)
@@ -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 "";