diff --git a/modules/dns.cpp b/modules/dns.cpp index b55e32da4..175575225 100644 --- a/modules/dns.cpp +++ b/modules/dns.cpp @@ -197,8 +197,12 @@ class Packet final if (pos + rdlength > input_size) throw SocketException("Unable to unpack TXT resource record"); - record.rdata = std::string(reinterpret_cast(input + pos), rdlength); - pos += rdlength; + auto txtlength = input[pos++]; + if (pos + txtlength > input_size) + throw SocketException("Unable to unpack TXT resource record"); + + record.rdata = Anope::string(reinterpret_cast(input + pos), txtlength); + pos += rdlength - 1; break; } case DNS::QUERY_SRV: