summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/res_comp.c
diff options
context:
space:
mode:
authordm <>1996-02-19 19:53:30 +0000
committerdm <>1996-02-19 19:53:30 +0000
commit543eeae2382e5de0b9518bdd9f7a75e5686fd056 (patch)
tree094165ba891a348ad41b10f58ccb57f1a01f8e74 /src/lib/libc/net/res_comp.c
parent4a12c1341f3a7e10bd98cebfe52fc96867f82baf (diff)
downloadopenbsd-543eeae2382e5de0b9518bdd9f7a75e5686fd056.tar.gz
openbsd-543eeae2382e5de0b9518bdd9f7a75e5686fd056.tar.bz2
openbsd-543eeae2382e5de0b9518bdd9f7a75e5686fd056.zip
netbsd: bind 4.9.3
Diffstat (limited to 'src/lib/libc/net/res_comp.c')
-rw-r--r--src/lib/libc/net/res_comp.c63
1 files changed, 42 insertions, 21 deletions
diff --git a/src/lib/libc/net/res_comp.c b/src/lib/libc/net/res_comp.c
index 9d7bbecdda..2d81327aaf 100644
--- a/src/lib/libc/net/res_comp.c
+++ b/src/lib/libc/net/res_comp.c
@@ -1,4 +1,4 @@
1/* $NetBSD: res_comp.c,v 1.6 1995/02/25 06:20:55 cgd Exp $ */ 1/* $NetBSD: res_comp.c,v 1.7 1996/02/02 15:22:26 mrg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1985, 1993 4 * Copyright (c) 1985, 1993
@@ -56,9 +56,9 @@
56#if defined(LIBC_SCCS) && !defined(lint) 56#if defined(LIBC_SCCS) && !defined(lint)
57#if 0 57#if 0
58static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; 58static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
59static char rcsid[] = "$Id: res_comp.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel "; 59static char rcsid[] = "$Id: res_comp.c,v 8.3 1995/12/06 20:34:50 vixie Exp ";
60#else 60#else
61static char rcsid[] = "$NetBSD: res_comp.c,v 1.6 1995/02/25 06:20:55 cgd Exp $"; 61static char rcsid[] = "$NetBSD: res_comp.c,v 1.7 1996/02/02 15:22:26 mrg Exp $";
62#endif 62#endif
63#endif /* LIBC_SCCS and not lint */ 63#endif /* LIBC_SCCS and not lint */
64 64
@@ -67,8 +67,11 @@ static char rcsid[] = "$NetBSD: res_comp.c,v 1.6 1995/02/25 06:20:55 cgd Exp $";
67#include <netinet/in.h> 67#include <netinet/in.h>
68#include <resolv.h> 68#include <resolv.h>
69#include <stdio.h> 69#include <stdio.h>
70#include <ctype.h>
71#include <unistd.h>
72#include <string.h>
70 73
71static int dn_find(); 74static int dn_find __P((u_char *, u_char *, u_char **, u_char **));
72 75
73/* 76/*
74 * Expand compressed domain name 'comp_dn' to full domain name. 77 * Expand compressed domain name 'comp_dn' to full domain name.
@@ -77,18 +80,20 @@ static int dn_find();
77 * 'exp_dn' is a pointer to a buffer of size 'length' for the result. 80 * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
78 * Return size of compressed name or -1 if there was an error. 81 * Return size of compressed name or -1 if there was an error.
79 */ 82 */
83int
80dn_expand(msg, eomorig, comp_dn, exp_dn, length) 84dn_expand(msg, eomorig, comp_dn, exp_dn, length)
81 const u_char *msg, *eomorig, *comp_dn; 85 const u_char *msg, *eomorig, *comp_dn;
82 u_char *exp_dn; 86 char *exp_dn;
83 int length; 87 int length;
84{ 88{
85 register u_char *cp, *dn; 89 register const u_char *cp;
90 register char *dn;
86 register int n, c; 91 register int n, c;
87 u_char *eom; 92 char *eom;
88 int len = -1, checked = 0; 93 int len = -1, checked = 0;
89 94
90 dn = exp_dn; 95 dn = exp_dn;
91 cp = (u_char *)comp_dn; 96 cp = comp_dn;
92 eom = exp_dn + length; 97 eom = exp_dn + length;
93 /* 98 /*
94 * fetch next label in domain name 99 * fetch next label in domain name
@@ -108,23 +113,23 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length)
108 return (-1); 113 return (-1);
109 checked += n + 1; 114 checked += n + 1;
110 while (--n >= 0) { 115 while (--n >= 0) {
111 if ((c = *cp++) == '.') { 116 if ((c = *cp++) == '.' || c == '\\') {
112 if (dn + n + 2 >= eom) 117 if (dn + n + 2 >= eom)
113 return (-1); 118 return (-1);
114 *dn++ = '\\'; 119 *dn++ = '\\';
115 } 120 }
116 *dn++ = c; 121 *dn++ = c;
117 if (cp >= eomorig) /* out of range */ 122 if (cp >= eomorig) /* out of range */
118 return(-1); 123 return (-1);
119 } 124 }
120 break; 125 break;
121 126
122 case INDIR_MASK: 127 case INDIR_MASK:
123 if (len < 0) 128 if (len < 0)
124 len = cp - comp_dn + 1; 129 len = cp - comp_dn + 1;
125 cp = (u_char *)msg + (((n & 0x3f) << 8) | (*cp & 0xff)); 130 cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff));
126 if (cp < msg || cp >= eomorig) /* out of range */ 131 if (cp < msg || cp >= eomorig) /* out of range */
127 return(-1); 132 return (-1);
128 checked += 2; 133 checked += 2;
129 /* 134 /*
130 * Check for loops in the compressed name; 135 * Check for loops in the compressed name;
@@ -140,6 +145,9 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length)
140 } 145 }
141 } 146 }
142 *dn = '\0'; 147 *dn = '\0';
148 for (dn = exp_dn; (c = *dn) != '\0'; dn++)
149 if (isascii(c) && isspace(c))
150 return (-1);
143 if (len < 0) 151 if (len < 0)
144 len = cp - comp_dn; 152 len = cp - comp_dn;
145 return (len); 153 return (len);
@@ -157,8 +165,9 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length)
157 * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' 165 * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
158 * is NULL, we don't update the list. 166 * is NULL, we don't update the list.
159 */ 167 */
168int
160dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) 169dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
161 const u_char *exp_dn; 170 const char *exp_dn;
162 u_char *comp_dn, **dnptrs, **lastdnptr; 171 u_char *comp_dn, **dnptrs, **lastdnptr;
163 int length; 172 int length;
164{ 173{
@@ -170,6 +179,7 @@ dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
170 dn = (u_char *)exp_dn; 179 dn = (u_char *)exp_dn;
171 cp = comp_dn; 180 cp = comp_dn;
172 eob = cp + length; 181 eob = cp + length;
182 lpp = cpp = NULL;
173 if (dnptrs != NULL) { 183 if (dnptrs != NULL) {
174 if ((msg = *dnptrs++) != NULL) { 184 if ((msg = *dnptrs++) != NULL) {
175 for (cpp = dnptrs; *cpp != NULL; cpp++) 185 for (cpp = dnptrs; *cpp != NULL; cpp++)
@@ -235,13 +245,14 @@ dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
235/* 245/*
236 * Skip over a compressed domain name. Return the size or -1. 246 * Skip over a compressed domain name. Return the size or -1.
237 */ 247 */
248int
238__dn_skipname(comp_dn, eom) 249__dn_skipname(comp_dn, eom)
239 const u_char *comp_dn, *eom; 250 const u_char *comp_dn, *eom;
240{ 251{
241 register u_char *cp; 252 register const u_char *cp;
242 register int n; 253 register int n;
243 254
244 cp = (u_char *)comp_dn; 255 cp = comp_dn;
245 while (cp < eom && (n = *cp++)) { 256 while (cp < eom && (n = *cp++)) {
246 /* 257 /*
247 * check for indirection 258 * check for indirection
@@ -263,6 +274,15 @@ __dn_skipname(comp_dn, eom)
263 return (cp - comp_dn); 274 return (cp - comp_dn);
264} 275}
265 276
277static int
278mklower(ch)
279 register int ch;
280{
281 if (isascii(ch) && isupper(ch))
282 return (tolower(ch));
283 return (ch);
284}
285
266/* 286/*
267 * Search for expanded name from a list of previously compressed names. 287 * Search for expanded name from a list of previously compressed names.
268 * Return the offset from msg if found or -1. 288 * Return the offset from msg if found or -1.
@@ -292,7 +312,7 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr)
292 goto next; 312 goto next;
293 if (*dn == '\\') 313 if (*dn == '\\')
294 dn++; 314 dn++;
295 if (*dn++ != *cp++) 315 if (mklower(*dn++) != mklower(*cp++))
296 goto next; 316 goto next;
297 } 317 }
298 if ((n = *dn++) == '\0' && *cp == '\0') 318 if ((n = *dn++) == '\0' && *cp == '\0')
@@ -301,11 +321,12 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr)
301 continue; 321 continue;
302 goto next; 322 goto next;
303 323
304 default: /* illegal type */
305 return (-1);
306
307 case INDIR_MASK: /* indirection */ 324 case INDIR_MASK: /* indirection */
308 cp = msg + (((n & 0x3f) << 8) | *cp); 325 cp = msg + (((n & 0x3f) << 8) | *cp);
326 break;
327
328 default: /* illegal type */
329 return (-1);
309 } 330 }
310 } 331 }
311 if (*dn == '\0') 332 if (*dn == '\0')
@@ -325,7 +346,7 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr)
325 346
326u_short 347u_short
327_getshort(msgp) 348_getshort(msgp)
328 register u_char *msgp; 349 register const u_char *msgp;
329{ 350{
330 register u_int16_t u; 351 register u_int16_t u;
331 352
@@ -335,7 +356,7 @@ _getshort(msgp)
335 356
336u_int32_t 357u_int32_t
337_getlong(msgp) 358_getlong(msgp)
338 register u_char *msgp; 359 register const u_char *msgp;
339{ 360{
340 register u_int32_t u; 361 register u_int32_t u;
341 362