Source-Changes-HG archive

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

[src/netbsd-1-6]: src/lib/libc/net Pull up revision 1.22 (requested by itojun...



details:   https://anonhg.NetBSD.org/src/rev/2fbf86b0d453
branches:  netbsd-1-6
changeset: 529009:2fbf86b0d453
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sat Aug 17 15:44:50 2002 +0000

description:
Pull up revision 1.22 (requested by itojun in ticket #693):
correct bad practice in the code - it uses two changing variables
to manage buffer (buf and buflen).  we eliminate buflen and use
fixed point (ep) as the ending pointer.
this fix is NOT critical.

diffstat:

 lib/libc/net/res_mkquery.c |  32 +++++++++++++++-----------------
 1 files changed, 15 insertions(+), 17 deletions(-)

diffs (107 lines):

diff -r e59826f1cc7f -r 2fbf86b0d453 lib/libc/net/res_mkquery.c
--- a/lib/libc/net/res_mkquery.c        Sat Aug 17 15:44:41 2002 +0000
+++ b/lib/libc/net/res_mkquery.c        Sat Aug 17 15:44:50 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: res_mkquery.c,v 1.21 2000/12/20 18:47:37 christos Exp $        */
+/*     $NetBSD: res_mkquery.c,v 1.21.4.1 2002/08/17 15:44:50 lukem Exp $       */
 
 /*-
  * Copyright (c) 1985, 1993
@@ -59,7 +59,7 @@
 static char sccsid[] = "@(#)res_mkquery.c      8.1 (Berkeley) 6/4/93";
 static char rcsid[] = "Id: res_mkquery.c,v 8.5 1996/08/27 08:33:28 vixie Exp ";
 #else
-__RCSID("$NetBSD: res_mkquery.c,v 1.21 2000/12/20 18:47:37 christos Exp $");
+__RCSID("$NetBSD: res_mkquery.c,v 1.21.4.1 2002/08/17 15:44:50 lukem Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -98,7 +98,7 @@
        int buflen;             /* size of buffer */
 {
        register HEADER *hp;
-       register u_char *cp;
+       register u_char *cp, *ep;
        register int n;
        u_char *dnptrs[20], **dpp, **lastdnptr;
 
@@ -136,7 +136,7 @@
        hp->rd = (_res.options & RES_RECURSE) != 0;
        hp->rcode = NOERROR;
        cp = buf + HFIXEDSZ;
-       buflen -= HFIXEDSZ;
+       ep = buf + buflen;
        dpp = dnptrs;
        *dpp++ = buf;
        *dpp++ = NULL;
@@ -147,12 +147,12 @@
        switch (op) {
        case QUERY:     /*FALLTHROUGH*/
        case NS_NOTIFY_OP:
-               if ((buflen -= QFIXEDSZ) < 0)
+               if (ep - cp < QFIXEDSZ)
                        return (-1);
-               if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
+               if ((n = dn_comp(dname, cp, ep - cp - QFIXEDSZ, dnptrs,
+                   lastdnptr)) < 0)
                        return (-1);
                cp += n;
-               buflen -= n;
                __putshort(type, cp);
                cp += sizeof(u_int16_t);
                __putshort(class, cp);
@@ -163,12 +163,12 @@
                /*
                 * Make an additional record for completion domain.
                 */
-               buflen -= RRFIXEDSZ;
-               if ((n = dn_comp((const char *)data, cp, buflen, dnptrs,
-                   lastdnptr)) < 0)
+               if (ep - cp < RRFIXEDSZ)
+                       return (-1);
+               if ((n = dn_comp((const char *)data, cp, ep - cp - RRFIXEDSZ,
+                   dnptrs, lastdnptr)) < 0)
                        return (-1);
                cp += n;
-               buflen -= n;
                __putshort(T_NULL, cp);
                cp += sizeof(u_int16_t);
                __putshort(class, cp);
@@ -184,7 +184,7 @@
                /*
                 * Initialize answer section
                 */
-               if (buflen < 1 + RRFIXEDSZ + datalen)
+               if (ep - cp < 1 + RRFIXEDSZ + datalen)
                        return (-1);
                *cp++ = '\0';   /* no domain name */
                __putshort(type, cp);
@@ -217,17 +217,16 @@
        int anslen;             /* answer buffer length */
 {
        register HEADER *hp;
-       register u_char *cp;
+       register u_char *cp, *ep;
 
        hp = (HEADER *)(void *)buf;
        cp = buf + n0;
-       buflen -= n0;
+       ep = buf + buflen;
 
-       if (buflen < 1 + RRFIXEDSZ)
+       if (ep - cp < 1 + RRFIXEDSZ)
                return -1;
 
        *cp++ = 0;      /* "." */
-       buflen--;
 
        __putshort(T_OPT, cp);  /* TYPE */
        cp += INT16SZ;
@@ -240,7 +239,6 @@
        __putshort(0, cp);      /* RDLEN */
        cp += INT16SZ;
        hp->arcount = htons(ntohs(hp->arcount) + 1);
-       buflen -= RRFIXEDSZ;
 
        return cp - buf;
 }



Home | Main Index | Thread Index | Old Index