I've also sent this upstream, https://bugs.busybox.net/show_bug.cgi?id=5342
but I don't know how long it takes for fixes to filter down.

In short, res_query rejects DNS responses where the first answer in a packet
does not have exactly the same type as the original question, which breaks
T_ANY and T_CNAME logic. Most code uses gethostinfo/gethostbyname routines
which avoids this, but anyone who does use res_query (and res_search, which
ends up calling res_query) will encounter this.

Additionally, when it rejects such responses, it does not return an error -
it returns the received packet length - but does not fill in the packet
contents, leading to erroneous onwards processing.

This patch fixes both these issues.  See the upstream bug report for a test
case demonstrating both the problem and the patch.

Cheers,
Chris.

toolchain/uClibc/patches-0.9.33.2/510-resolv-any.patch


Signed-off-by: Chris Luke <chr...@flirble.org>

Index: uClibc-0.9.33.2/libc/inet/resolv.c
===================================================================
--- uClibc-0.9.33.2.orig/libc/inet/resolv.c     2012-07-07
11:05:29.931149126 -0400
+++ uClibc-0.9.33.2/libc/inet/resolv.c  2012-07-07 11:06:17.375149135 -0400
@@ -3741,10 +3741,16 @@
 
        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;




_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to