mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] dns: check length field in tcp response message
@ 2023-03-22 12:29 Alexey Kodanev
  2023-03-22 13:16 ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: Alexey Kodanev @ 2023-03-22 12:29 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 'alen', it will result
in an out-of-bounds reading during parsing, because 'alen' will
be passed to __dns_parse() later:

    __dns_parse(abuf[i], alens[i], dns_parse_callback, &ctx);

To fix this, limit 'alen' to the size of the received buffer.
---
 src/network/res_msend.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/network/res_msend.c b/src/network/res_msend.c
index fef7e3a2..291853de 100644
--- a/src/network/res_msend.c
+++ b/src/network/res_msend.c
@@ -297,6 +297,7 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
 			int rcode = answers[i][3] & 15;
 			if (rcode != 0 && rcode != 3)
 				goto out;
+			if (alen > asize) alen = asize;
 
 			/* Storing the length here commits the accepted answer.
 			 * Immediately close TCP socket so as not to consume
-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-29 15:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-22 12:29 [musl] [PATCH] dns: check length field in tcp response message Alexey Kodanev
2023-03-22 13:16 ` Rich Felker
2023-03-22 13:48   ` Alexey Kodanev
2023-03-22 14:07     ` Rich Felker
2023-05-08 16:25   ` Alexey Izbyshev
2024-02-29 10:49     ` Alexey Izbyshev
2024-02-29 15:36       ` Rich Felker

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).