mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH v2] dns: check length field in tcp response message
@ 2023-03-22 14:48 Alexey Kodanev
  0 siblings, 0 replies; only message in thread
From: Alexey Kodanev @ 2023-03-22 14:48 UTC (permalink / raw)
  To: musl; +Cc: Alexey Kodanev

The received length field in the message may be greater than the
size of the 'answer' buffer in which the message resides. Currently,
ABUF_SIZE is 768. And if we get a larger 'alens[i]', it will result
in an out-of-bounds reading in __dns_parse().

To fix this, limit the length to the size of the received buffer.
---
v2: move the check to name_from_dns()

 src/network/lookup_name.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c
index 5f6867cb..e324f39d 100644
--- a/src/network/lookup_name.c
+++ b/src/network/lookup_name.c
@@ -179,6 +179,7 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static
 
 	for (i=nq-1; i>=0; i--) {
 		ctx.rrtype = qtypes[i];
+		if (alens[i] > sizeof(abuf[i])) alens[i] = sizeof(abuf[i]);
 		__dns_parse(abuf[i], alens[i], dns_parse_callback, &ctx);
 	}
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-22 14:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-22 14:48 [musl] [PATCH v2] dns: check length field in tcp response message Alexey Kodanev

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).