[PATCH] res_query() silently rejects responses against T_ANY DNS questions.

Chris Luke chrisy at flirble.org
Mon Jul 9 01:01:33 UTC 2012


res_query() is rejecting T_ANY and T_CNAME requests since they give answers with a different type. It also doesn't reject them cleanly, returning the length of the packet that would be returned (but not filling in the buffer) instead of -1.

This commit fixes that by allowing T_ANY questions to have any type of answer and T_A or T_AAAA questions to have T_CNAME answers.

It also returns -1 if it otherwise rejects the response.

See https://bugs.busybox.net/show_bug.cgi?id=5342 which has a test case for this.

Patch has been tested on OpenWrt and i386 buildroot.

Signed-off-by: Chris Luke <chrisy at flirble.org>
---
  libc/inet/resolv.c |    8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index e9f550b..06af2dc 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -3736,10 +3736,16 @@ int res_query(const char *dname, int class, int type,
  
         free(a.dotted);
  
-       if (a.atype == type) { /* CNAME */
+       /* Copy the answer only if the type asked for is the same as the answer,
+        * we asked for T_ANY, or an A or AAAA returned a CNAME first.
+        */
+       if (a.atype == type || type == T_ANY || (a.atype == T_CNAME && (type == T_A || type == T_AAAA))) {
                 if (i > anslen)
                         i = anslen;
                 memcpy(answer, packet, i);
+       } else {
+               h_errno = NO_DATA;
+               i = -1;
         }
         free(packet);
         return i;
-- 
1.7.9.5




More information about the uClibc mailing list