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 77327ed064,
which fixed the only other __dns_parse call site.
This commit is contained in:
Alexey Izbyshev 2023-05-08 19:03:46 +03:00 committed by Rich Felker
parent d3a61059c0
commit 5c653ccaa1

View file

@ -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;