Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-6]: src/dist/bind/lib/resolv Pull up revision 1.3 (requested by...



details:   https://anonhg.NetBSD.org/src/rev/c7e2cd3bc230
branches:  netbsd-1-6
changeset: 528241:c7e2cd3bc230
user:      lukem <lukem%NetBSD.org@localhost>
date:      Fri Jun 28 11:58:30 2002 +0000

description:
Pull up revision 1.3 (requested by itojun in ticket #387):
Update to BIND 8.3.3.  Fixes buffer overrun in resolver code.

diffstat:

 dist/bind/lib/resolv/res_query.c |  40 +++++++++++++++++++++++++++++++---------
 1 files changed, 31 insertions(+), 9 deletions(-)

diffs (113 lines):

diff -r dcf424351504 -r c7e2cd3bc230 dist/bind/lib/resolv/res_query.c
--- a/dist/bind/lib/resolv/res_query.c  Fri Jun 28 11:58:22 2002 +0000
+++ b/dist/bind/lib/resolv/res_query.c  Fri Jun 28 11:58:30 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: res_query.c,v 1.2 2001/01/27 07:22:05 itojun Exp $     */
+/*     $NetBSD: res_query.c,v 1.2.2.1 2002/06/28 11:58:30 lukem Exp $  */
 
 /*
  * Copyright (c) 1988, 1993
@@ -72,7 +72,7 @@
 
 #if defined(LIBC_SCCS) && !defined(lint)
 static const char sccsid[] = "@(#)res_query.c  8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "Id: res_query.c,v 8.20 2000/02/29 05:39:12 vixie Exp";
+static const char rcsid[] = "Id: res_query.c,v 8.23 2001/09/24 13:50:29 marka Exp";
 #endif /* LIBC_SCCS and not lint */
 
 #include "port_before.h"
@@ -119,7 +119,11 @@
        u_char buf[MAXPACKET];
        HEADER *hp = (HEADER *) answer;
        int n;
+       u_int oflags;
 
+       oflags = statp->_flags;
+
+again:
        hp->rcode = NOERROR;    /* default */
 
 #ifdef DEBUG
@@ -129,6 +133,11 @@
 
        n = res_nmkquery(statp, QUERY, name, class, type, NULL, 0, NULL,
                         buf, sizeof(buf));
+#ifdef RES_USE_EDNS0
+       if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 &&
+           (statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0)
+               n = res_nopt(statp, n, buf, sizeof(buf), anslen);
+#endif
        if (n <= 0) {
 #ifdef DEBUG
                if (statp->options & RES_DEBUG)
@@ -139,6 +148,16 @@
        }
        n = res_nsend(statp, buf, n, answer, anslen);
        if (n < 0) {
+#ifdef RES_USE_EDNS0
+               /* if the query choked with EDNS0, retry without EDNS0 */
+               if ((statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0 &&
+                   ((oflags ^ statp->_flags) & RES_F_EDNS0ERR) != 0) {
+                       statp->_flags |= RES_F_EDNS0ERR;
+                       if (statp->options & RES_DEBUG)
+                               printf(";; res_nquery: retry without EDNS0\n");
+                       goto again;
+               }
+#endif
 #ifdef DEBUG
                if (statp->options & RES_DEBUG)
                        printf(";; res_query: send error\n");
@@ -195,6 +214,7 @@
        int trailing_dot, ret, saved_herrno;
        int got_nodata = 0, got_servfail = 0, root_on_list = 0;
        int tried_as_is = 0;
+       int searched = 0;
 
        errno = 0;
        RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);  /* True if we never query. */
@@ -238,6 +258,7 @@
                for (domain = (const char * const *)statp->dnsrch;
                     *domain && !done;
                     domain++) {
+                       searched = 1;
 
                        if (domain[0][0] == '\0' ||
                            (domain[0][0] == '.' && domain[0][1] == '\0'))
@@ -295,11 +316,11 @@
        }
 
        /*
-        * If the name has any dots at all, and no earlier 'as-is' query 
-        * for the name, and "." is not on the search list, then try an as-is
-        * query now.
+        * If the query has not already been tried as is then try it
+        * unless RES_NOTLDQUERY is set and there were no dots.
         */
-       if (statp->ndots && !(tried_as_is || root_on_list)) {
+       if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0) &&
+           !(tried_as_is || root_on_list)) {
                ret = res_nquerydomain(statp, name, NULL, class, type,
                                       answer, anslen);
                if (ret > 0)
@@ -385,17 +406,18 @@
        setbuf(fp, NULL);
        buf[sizeof(buf) - 1] = '\0';
        while (fgets(buf, sizeof(buf), fp)) {
-               for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1)
+               for (cp1 = buf; *cp1 && !isspace((unsigned char)*cp1); ++cp1)
                        ;
                if (!*cp1)
                        break;
                *cp1 = '\0';
                if (ns_samename(buf, name) == 1) {
-                       while (isspace(*++cp1))
+                       while (isspace((unsigned char)*++cp1))
                                ;
                        if (!*cp1)
                                break;
-                       for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2)
+                       for (cp2 = cp1 + 1; *cp2 &&
+                            !isspace((unsigned char)*cp2); ++cp2)
                                ;
                        *cp2 = '\0';
                        strncpy(dst, cp1, siz - 1);



Home | Main Index | Thread Index | Old Index