From 4ec95e70fe9681dced8f9cc95b9694fc135df416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jerry=20Lundstr=C3=B6m?= Date: Thu, 2 Jun 2022 10:54:30 +0200 Subject: [PATCH] FQDN parsing - Fix #109: Need 4 times the buffer due to possible escaping --- src/dns.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dns.h b/src/dns.h index 2542f7f..1dc4401 100644 --- a/src/dns.h +++ b/src/dns.h @@ -112,7 +112,7 @@ class DNSMessage { class Name { public: - char fqdn[512]; + char fqdn[2048]; // escaping needs *4 the space int labels; Name() @@ -243,7 +243,6 @@ class DNSMessage { int savedoffs = 0; int n = get_ubyte(offs++); char* out = &name.fqdn[0]; - int size = sizeof(name.fqdn); if (n == 0) out[p++] = '.'; @@ -262,7 +261,8 @@ class DNSMessage { } // if the string is too long restart and mess it up - if (n + 20 + p > size / 2) + // check if we can fit a fully escaped label + . and reserve for zeroing it later + if (p + (n * 4) + 1 > sizeof(name.fqdn) - 1) p = 0; while (n-- > 0) {