From 71c62ea7cb95ce987a7bca41181bf963ecf12d39 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 25 Dec 2021 10:58:49 +0000 Subject: Make packing PTR queries a bit more robust. There is no first party modules which could be compromised before this check was added but its better to be safe wherever possible. --- src/coremods/core_dns.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/coremods/core_dns.cpp b/src/coremods/core_dns.cpp index 8ebc1b57d..f3febc36b 100644 --- a/src/coremods/core_dns.cpp +++ b/src/coremods/core_dns.cpp @@ -279,7 +279,7 @@ class Packet : public Query unsigned short Pack(unsigned char* output, unsigned short output_size) { if (output_size < HEADER_LENGTH) - throw Exception("Unable to pack packet"); + throw Exception("Unable to pack oversized packet header"); unsigned short pos = 0; @@ -302,7 +302,8 @@ class Packet : public Query if (q.type == QUERY_PTR) { irc::sockets::sockaddrs ip; - irc::sockets::aptosa(q.name, 0, ip); + if (!irc::sockets::aptosa(q.name, 0, ip)) + throw Exception("Unable to pack packet with malformed IP for PTR lookup"); if (q.name.find(':') != std::string::npos) { @@ -333,7 +334,7 @@ class Packet : public Query this->PackName(output, output_size, pos, q.name); if (pos + 4 >= output_size) - throw Exception("Unable to pack packet"); + throw Exception("Unable to pack oversized packet body"); short s = htons(q.type); memcpy(&output[pos], &s, 2); -- cgit v1.3.1-10-gc9f91