Skip to content

Commit 903284c

Browse files
author
leoparente
authored
Don't limit dns wire data by size (#254)
* Don't limit dns wire data by size * Check buffer size minimum
1 parent 2b18119 commit 903284c

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

src/handlers/dns/DnsStreamHandler.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,19 @@ void DnsStreamHandler::process_udp_packet_cb(pcpp::Packet &payload, PacketDirect
180180

181181
void TcpSessionData::receive_dns_wire_data(const uint8_t *data, size_t len)
182182
{
183-
const size_t MIN_DNS_QUERY_SIZE = 17;
184-
const size_t MAX_DNS_QUERY_SIZE = 512;
185-
186183
_buffer.append(reinterpret_cast<const char *>(data), len);
187184

188185
for (;;) {
189186
std::uint16_t size;
190187

191-
if (_buffer.size() < sizeof(size)) {
188+
// if buffer size < min DNS size, we know we need more data
189+
if (_buffer.size() < MIN_DNS_QUERY_SIZE + sizeof(size)) {
192190
break;
193191
}
194192

195193
// dns packet size is in network byte order.
196194
size = static_cast<unsigned char>(_buffer[1]) | static_cast<unsigned char>(_buffer[0]) << 8;
197195

198-
// ensure we never allocate more than max
199-
if (size < MIN_DNS_QUERY_SIZE || size > MAX_DNS_QUERY_SIZE) {
200-
break;
201-
}
202-
203196
if (_buffer.size() >= sizeof(size) + size) {
204197
auto data = std::make_unique<uint8_t[]>(size);
205198
std::memcpy(data.get(), _buffer.data() + sizeof(size), size);

src/handlers/dns/DnsStreamHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class DnsMetricsManager final : public visor::AbstractMetricsManager<DnsMetricsB
207207
class TcpSessionData final
208208
{
209209
public:
210+
static constexpr size_t MIN_DNS_QUERY_SIZE = 17;
210211
using got_msg_cb = std::function<void(std::unique_ptr<uint8_t[]> data, size_t size)>;
211212

212213
private:

0 commit comments

Comments
 (0)