diff options
author | dm <dm@cvs.openbsd.org> | 1996-02-19 19:54:44 +0000 |
---|---|---|
committer | dm <dm@cvs.openbsd.org> | 1996-02-19 19:54:44 +0000 |
commit | 34dfcd3c571a64de57872aa758d1b228d7b22a02 (patch) | |
tree | 22b14dd50dff4fc41ec5c5f2ee3e20f4b7f1d141 /lib/libc/net/res_comp.c | |
parent | d134390523f594c4e7f1b453b8026b993a1aeebb (diff) |
netbsd: bind 4.9.3
Diffstat (limited to 'lib/libc/net/res_comp.c')
-rw-r--r-- | lib/libc/net/res_comp.c | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/lib/libc/net/res_comp.c b/lib/libc/net/res_comp.c index 9d7bbecdda5..2d81327aafd 100644 --- a/lib/libc/net/res_comp.c +++ b/lib/libc/net/res_comp.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_comp.c,v 1.6 1995/02/25 06:20:55 cgd Exp $ */ +/* $NetBSD: res_comp.c,v 1.7 1996/02/02 15:22:26 mrg Exp $ */ /*- * Copyright (c) 1985, 1993 @@ -56,9 +56,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #if 0 static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$Id: res_comp.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel "; +static char rcsid[] = "$Id: res_comp.c,v 8.3 1995/12/06 20:34:50 vixie Exp "; #else -static char rcsid[] = "$NetBSD: res_comp.c,v 1.6 1995/02/25 06:20:55 cgd Exp $"; +static char rcsid[] = "$NetBSD: res_comp.c,v 1.7 1996/02/02 15:22:26 mrg Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -67,8 +67,11 @@ static char rcsid[] = "$NetBSD: res_comp.c,v 1.6 1995/02/25 06:20:55 cgd Exp $"; #include <netinet/in.h> #include <resolv.h> #include <stdio.h> +#include <ctype.h> +#include <unistd.h> +#include <string.h> -static int dn_find(); +static int dn_find __P((u_char *, u_char *, u_char **, u_char **)); /* * Expand compressed domain name 'comp_dn' to full domain name. @@ -77,18 +80,20 @@ static int dn_find(); * 'exp_dn' is a pointer to a buffer of size 'length' for the result. * Return size of compressed name or -1 if there was an error. */ +int dn_expand(msg, eomorig, comp_dn, exp_dn, length) const u_char *msg, *eomorig, *comp_dn; - u_char *exp_dn; + char *exp_dn; int length; { - register u_char *cp, *dn; + register const u_char *cp; + register char *dn; register int n, c; - u_char *eom; + char *eom; int len = -1, checked = 0; dn = exp_dn; - cp = (u_char *)comp_dn; + cp = comp_dn; eom = exp_dn + length; /* * fetch next label in domain name @@ -108,23 +113,23 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) return (-1); checked += n + 1; while (--n >= 0) { - if ((c = *cp++) == '.') { + if ((c = *cp++) == '.' || c == '\\') { if (dn + n + 2 >= eom) return (-1); *dn++ = '\\'; } *dn++ = c; if (cp >= eomorig) /* out of range */ - return(-1); + return (-1); } break; case INDIR_MASK: if (len < 0) len = cp - comp_dn + 1; - cp = (u_char *)msg + (((n & 0x3f) << 8) | (*cp & 0xff)); + cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff)); if (cp < msg || cp >= eomorig) /* out of range */ - return(-1); + return (-1); checked += 2; /* * Check for loops in the compressed name; @@ -140,6 +145,9 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) } } *dn = '\0'; + for (dn = exp_dn; (c = *dn) != '\0'; dn++) + if (isascii(c) && isspace(c)) + return (-1); if (len < 0) len = cp - comp_dn; return (len); @@ -157,8 +165,9 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' * is NULL, we don't update the list. */ +int dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) - const u_char *exp_dn; + const char *exp_dn; u_char *comp_dn, **dnptrs, **lastdnptr; int length; { @@ -170,6 +179,7 @@ dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) dn = (u_char *)exp_dn; cp = comp_dn; eob = cp + length; + lpp = cpp = NULL; if (dnptrs != NULL) { if ((msg = *dnptrs++) != NULL) { for (cpp = dnptrs; *cpp != NULL; cpp++) @@ -235,13 +245,14 @@ dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) /* * Skip over a compressed domain name. Return the size or -1. */ +int __dn_skipname(comp_dn, eom) const u_char *comp_dn, *eom; { - register u_char *cp; + register const u_char *cp; register int n; - cp = (u_char *)comp_dn; + cp = comp_dn; while (cp < eom && (n = *cp++)) { /* * check for indirection @@ -263,6 +274,15 @@ __dn_skipname(comp_dn, eom) return (cp - comp_dn); } +static int +mklower(ch) + register int ch; +{ + if (isascii(ch) && isupper(ch)) + return (tolower(ch)); + return (ch); +} + /* * Search for expanded name from a list of previously compressed names. * Return the offset from msg if found or -1. @@ -292,7 +312,7 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) goto next; if (*dn == '\\') dn++; - if (*dn++ != *cp++) + if (mklower(*dn++) != mklower(*cp++)) goto next; } if ((n = *dn++) == '\0' && *cp == '\0') @@ -301,11 +321,12 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) continue; goto next; - default: /* illegal type */ - return (-1); - case INDIR_MASK: /* indirection */ cp = msg + (((n & 0x3f) << 8) | *cp); + break; + + default: /* illegal type */ + return (-1); } } if (*dn == '\0') @@ -325,7 +346,7 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) u_short _getshort(msgp) - register u_char *msgp; + register const u_char *msgp; { register u_int16_t u; @@ -335,7 +356,7 @@ _getshort(msgp) u_int32_t _getlong(msgp) - register u_char *msgp; + register const u_char *msgp; { register u_int32_t u; |