mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Alexey Izbyshev <izbyshev@ispras.ru>
To: musl@lists.openwall.com
Subject: [musl] [PATCH] dns: handle early eof in tcp fallback
Date: Fri, 24 Feb 2023 23:48:55 +0300	[thread overview]
Message-ID: <20230224204855.234010-1-izbyshev@ispras.ru> (raw)

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];
-- 
2.39.1


                 reply	other threads:[~2023-02-24 20:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230224204855.234010-1-izbyshev@ispras.ru \
    --to=izbyshev@ispras.ru \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).