about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexey Izbyshev <izbyshev@ispras.ru>2023-05-08 19:03:46 +0300
committerRich Felker <dalias@aerifal.cx>2024-02-29 10:14:16 -0500
commit5c653ccaa1383db0c310abf66d5b6806e83ac18f (patch)
tree8c5d33b578c0baa2aad021f8b178d3dd31d3e61d /src
parentd3a61059c04bd82329707324fac0d48e191edbf4 (diff)
downloadmusl-5c653ccaa1383db0c310abf66d5b6806e83ac18f.tar.gz
musl-5c653ccaa1383db0c310abf66d5b6806e83ac18f.tar.xz
musl-5c653ccaa1383db0c310abf66d5b6806e83ac18f.zip
getnameinfo: fix calling __dns_parse with potentially too large rlen
__res_send returns the full answer length even if it didn't fit the
buffer, but __dns_parse expects the length of the filled part of the
buffer.

This is analogous to commit 77327ed064bd57b0e1865cd0e0364057ff4a53b4,
which fixed the only other __dns_parse call site.
Diffstat (limited to 'src')
-rw-r--r--src/network/getnameinfo.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/network/getnameinfo.c b/src/network/getnameinfo.c
index 7abe0fa9..133c15b3 100644
--- a/src/network/getnameinfo.c
+++ b/src/network/getnameinfo.c
@@ -162,8 +162,10 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl,
 			query[3] = 0; /* don't need AD flag */
 			int rlen = __res_send(query, qlen, reply, sizeof reply);
 			buf[0] = 0;
-			if (rlen > 0)
+			if (rlen > 0) {
+				if (rlen > sizeof reply) rlen = sizeof reply;
 				__dns_parse(reply, rlen, dns_parse_callback, buf);
+			}
 		}
 		if (!*buf) {
 			if (flags & NI_NAMEREQD) return EAI_NONAME;