From 1b4e84c56df0f8ca30f6bc05962a860f869e71df Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 19 May 2020 19:25:42 -0400 Subject: fix return value of res_send, res_query on errors from nameserver the internal __res_msend returns 0 on timeout without having obtained any conclusive answer, but in this case has not filled in meaningful anslen. res_send wrongly treated that as success, but returned a zero answer length. any reasonable caller would eventually end up treating that as an error when attempting to parse/validate it, but it should just be reported as an error. alternatively we could return the last-received inconclusive answer (typically servfail), but doing so would require internal changes in __res_msend. this may be considered later. --- src/network/res_send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/res_send.c b/src/network/res_send.c index b9cea0bf..ee4abf1f 100644 --- a/src/network/res_send.c +++ b/src/network/res_send.c @@ -3,7 +3,7 @@ int __res_send(const unsigned char *msg, int msglen, unsigned char *answer, int anslen) { int r = __res_msend(1, &msg, &msglen, &answer, &anslen, anslen); - return r<0 ? r : anslen; + return r<0 || !anslen ? -1 : anslen; } weak_alias(__res_send, res_send); -- cgit v1.2.1