From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26848 invoked from network); 24 Feb 2023 20:49:14 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 24 Feb 2023 20:49:14 -0000 Received: (qmail 24464 invoked by uid 550); 24 Feb 2023 20:49:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 24426 invoked from network); 24 Feb 2023 20:49:10 -0000 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 6743440737C1 From: Alexey Izbyshev To: musl@lists.openwall.com Date: Fri, 24 Feb 2023 23:48:55 +0300 Message-Id: <20230224204855.234010-1-izbyshev@ispras.ru> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Mail-Followup-To: musl@lists.openwall.com Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH] dns: handle early eof in tcp fallback 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