mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] dns: handle early eof in tcp fallback
@ 2023-02-24 20:48 Alexey Izbyshev
  0 siblings, 0 replies; only message in thread
From: Alexey Izbyshev @ 2023-02-24 20:48 UTC (permalink / raw)
  To: musl

A zero returned from recvmsg is currently treated as if some data were
received, so if a DNS server closes its TCP socket before sending the
full answer, __res_msend_rc will spin until the timeout elapses because
POLLIN event will be reported on each poll. Fix this by treating an
early EOF as an error.
 src/network/res_msend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/network/res_msend.c b/src/network/res_msend.c
index fef7e3a2..2643be22 100644
--- a/src/network/res_msend.c
+++ b/src/network/res_msend.c
@@ -287,7 +287,7 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
 			step_mh(&mh, apos[i]);
 			r = recvmsg(pfd[i].fd, &mh, 0);
-			if (r < 0) goto out;
+			if (r <= 0) goto out;
 			apos[i] += r;
 			if (apos[i] < 2) continue;
 			int alen = alen_buf[i][0]*256 + alen_buf[i][1];

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

only message in thread, other threads:[~2023-02-24 20:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-24 20:48 [musl] [PATCH] dns: handle early eof in tcp fallback Alexey Izbyshev

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

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