Fix very long DNS names (>64 bytes) potentially crashing the internal name resolving mechanism, the new limit is 256 bytes with proper boundary checking

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2024-06-03 13:29:06 +02:00
parent d66db4550e
commit af0468eb36
+3 -2
View File
@@ -449,7 +449,8 @@ static char *__attribute__((malloc)) ngethostbyname(const int sock, struct socka
// 3www6google3com -> www.google.com
static u_char * __attribute__((malloc)) __attribute__((nonnull(1,2,3))) name_fromDNS(unsigned char *reader, unsigned char *buffer, uint16_t *count)
{
unsigned char *name = calloc(MAXHOSTNAMELEN, sizeof(char));
const size_t MAXNAMELEN = 256;
unsigned char *name = calloc(MAXNAMELEN, sizeof(char));
unsigned int p = 0, jumped = 0;
// Initialize count
@@ -462,7 +463,7 @@ static u_char * __attribute__((malloc)) __attribute__((nonnull(1,2,3))) name_fro
// Instead, each label is preceded by a byte containing its length, and
// the name is terminated by a zero-length label representing the root
// zone.
while(*reader != 0)
while(*reader != 0 && p < MAXNAMELEN - 2)
{
if(*reader >= 0xC0)
{