summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/getrrsetbyname.c37
-rw-r--r--openbsd-compat/strlcat.c40
-rw-r--r--openbsd-compat/strlcpy.c40
-rw-r--r--openbsd-compat/vis.c36
4 files changed, 69 insertions, 84 deletions
diff --git a/openbsd-compat/getrrsetbyname.c b/openbsd-compat/getrrsetbyname.c
index 1a4d9c14b..3ba54e0da 100644
--- a/openbsd-compat/getrrsetbyname.c
+++ b/openbsd-compat/getrrsetbyname.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getrrsetbyname.c,v 1.4 2001/08/16 18:16:43 ho Exp $ */ 1/* $OpenBSD: getrrsetbyname.c,v 1.7 2003/03/07 07:34:14 itojun Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001 Jakob Schlyter. All rights reserved. 4 * Copyright (c) 2001 Jakob Schlyter. All rights reserved.
@@ -49,6 +49,8 @@
49 49
50#include "getrrsetbyname.h" 50#include "getrrsetbyname.h"
51 51
52/* #include "thread_private.h" */
53
52#define ANSWER_BUFFER_SIZE 1024*64 54#define ANSWER_BUFFER_SIZE 1024*64
53 55
54struct dns_query { 56struct dns_query {
@@ -76,10 +78,10 @@ struct dns_response {
76 struct dns_rr *additional; 78 struct dns_rr *additional;
77}; 79};
78 80
79static struct dns_response *parse_dns_response(const char *, int); 81static struct dns_response *parse_dns_response(const u_char *, int);
80static struct dns_query *parse_dns_qsection(const char *, int, const char **, 82static struct dns_query *parse_dns_qsection(const u_char *, int,
81 int); 83 const u_char **, int);
82static struct dns_rr *parse_dns_rrsection(const char *, int, const char **, 84static struct dns_rr *parse_dns_rrsection(const u_char *, int, const u_char **,
83 int); 85 int);
84 86
85static void free_dns_query(struct dns_query *); 87static void free_dns_query(struct dns_query *);
@@ -153,13 +155,15 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
153 unsigned int rdtype, unsigned int flags, 155 unsigned int rdtype, unsigned int flags,
154 struct rrsetinfo **res) 156 struct rrsetinfo **res)
155{ 157{
158 struct __res_state *_resp = &_res;
156 int result; 159 int result;
157 struct rrsetinfo *rrset = NULL; 160 struct rrsetinfo *rrset = NULL;
158 struct dns_response *response; 161 struct dns_response *response;
159 struct dns_rr *rr; 162 struct dns_rr *rr;
160 struct rdatainfo *rdata; 163 struct rdatainfo *rdata;
161 unsigned int length, index_ans, index_sig; 164 int length;
162 char answer[ANSWER_BUFFER_SIZE]; 165 unsigned int index_ans, index_sig;
166 u_char answer[ANSWER_BUFFER_SIZE];
163 167
164 /* check for invalid class and type */ 168 /* check for invalid class and type */
165 if (rdclass > 0xffff || rdtype > 0xffff) { 169 if (rdclass > 0xffff || rdtype > 0xffff) {
@@ -180,23 +184,24 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
180 } 184 }
181 185
182 /* initialize resolver */ 186 /* initialize resolver */
183 if ((_res.options & RES_INIT) == 0 && res_init() == -1) { 187 if ((_resp->options & RES_INIT) == 0 && res_init() == -1) {
184 result = ERRSET_FAIL; 188 result = ERRSET_FAIL;
185 goto fail; 189 goto fail;
186 } 190 }
187 191
188#ifdef DEBUG 192#ifdef DEBUG
189 _res.options |= RES_DEBUG; 193 _resp->options |= RES_DEBUG;
190#endif /* DEBUG */ 194#endif /* DEBUG */
191 195
192#ifdef RES_USE_DNSSEC 196#ifdef RES_USE_DNSSEC
193 /* turn on DNSSEC if EDNS0 is configured */ 197 /* turn on DNSSEC if EDNS0 is configured */
194 if (_res.options & RES_USE_EDNS0) 198 if (_resp->options & RES_USE_EDNS0)
195 _res.options |= RES_USE_DNSSEC; 199 _resp->options |= RES_USE_DNSSEC;
196#endif /* RES_USE_DNSEC */ 200#endif /* RES_USE_DNSEC */
197 201
198 /* make query */ 202 /* make query */
199 length = res_query(hostname, rdclass, rdtype, answer, sizeof(answer)); 203 length = res_query(hostname, (signed int) rdclass, (signed int) rdtype,
204 answer, sizeof(answer));
200 if (length < 0) { 205 if (length < 0) {
201 switch(h_errno) { 206 switch(h_errno) {
202 case HOST_NOT_FOUND: 207 case HOST_NOT_FOUND:
@@ -338,10 +343,10 @@ freerrset(struct rrsetinfo *rrset)
338 * DNS response parsing routines 343 * DNS response parsing routines
339 */ 344 */
340static struct dns_response * 345static struct dns_response *
341parse_dns_response(const char *answer, int size) 346parse_dns_response(const u_char *answer, int size)
342{ 347{
343 struct dns_response *resp; 348 struct dns_response *resp;
344 const char *cp; 349 const u_char *cp;
345 350
346 /* allocate memory for the response */ 351 /* allocate memory for the response */
347 resp = calloc(1, sizeof(*resp)); 352 resp = calloc(1, sizeof(*resp));
@@ -403,7 +408,7 @@ parse_dns_response(const char *answer, int size)
403} 408}
404 409
405static struct dns_query * 410static struct dns_query *
406parse_dns_qsection(const char *answer, int size, const char **cp, int count) 411parse_dns_qsection(const u_char *answer, int size, const u_char **cp, int count)
407{ 412{
408 struct dns_query *head, *curr, *prev; 413 struct dns_query *head, *curr, *prev;
409 int i, length; 414 int i, length;
@@ -449,7 +454,7 @@ parse_dns_qsection(const char *answer, int size, const char **cp, int count)
449} 454}
450 455
451static struct dns_rr * 456static struct dns_rr *
452parse_dns_rrsection(const char *answer, int size, const char **cp, int count) 457parse_dns_rrsection(const u_char *answer, int size, const u_char **cp, int count)
453{ 458{
454 struct dns_rr *head, *curr, *prev; 459 struct dns_rr *head, *curr, *prev;
455 int i, length; 460 int i, length;
diff --git a/openbsd-compat/strlcat.c b/openbsd-compat/strlcat.c
index 3a9b5d1a7..8df757730 100644
--- a/openbsd-compat/strlcat.c
+++ b/openbsd-compat/strlcat.c
@@ -1,37 +1,26 @@
1/* $OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $ */ 1/* $OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> 4 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
5 * All rights reserved.
6 * 5 *
7 * Redistribution and use in source and binary forms, with or without 6 * Permission to use, copy, modify, and distribute this software for any
8 * modification, are permitted provided that the following conditions 7 * purpose with or without fee is hereby granted, provided that the above
9 * are met: 8 * copyright notice and this permission notice appear in all copies.
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 * 9 *
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 10 * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
19 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 12 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
21 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 13 * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 17 */
29 18
30#include "includes.h" 19#include "includes.h"
31#ifndef HAVE_STRLCAT 20#ifndef HAVE_STRLCAT
32 21
33#if defined(LIBC_SCCS) && !defined(lint) 22#if defined(LIBC_SCCS) && !defined(lint)
34static char *rcsid = "$OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $"; 23static char *rcsid = "$OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp $";
35#endif /* LIBC_SCCS and not lint */ 24#endif /* LIBC_SCCS and not lint */
36 25
37#include <sys/types.h> 26#include <sys/types.h>
@@ -46,10 +35,7 @@ static char *rcsid = "$OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp
46 * If retval >= siz, truncation occurred. 35 * If retval >= siz, truncation occurred.
47 */ 36 */
48size_t 37size_t
49strlcat(dst, src, siz) 38strlcat(char *dst, const char *src, size_t siz)
50 char *dst;
51 const char *src;
52 size_t siz;
53{ 39{
54 register char *d = dst; 40 register char *d = dst;
55 register const char *s = src; 41 register const char *s = src;
diff --git a/openbsd-compat/strlcpy.c b/openbsd-compat/strlcpy.c
index 2f87eca44..fbb4f8ae2 100644
--- a/openbsd-compat/strlcpy.c
+++ b/openbsd-compat/strlcpy.c
@@ -1,37 +1,26 @@
1/* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */ 1/* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> 4 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
5 * All rights reserved.
6 * 5 *
7 * Redistribution and use in source and binary forms, with or without 6 * Permission to use, copy, modify, and distribute this software for any
8 * modification, are permitted provided that the following conditions 7 * purpose with or without fee is hereby granted, provided that the above
9 * are met: 8 * copyright notice and this permission notice appear in all copies.
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 * 9 *
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 10 * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
19 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 12 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
21 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 13 * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 17 */
29 18
30#include "includes.h" 19#include "includes.h"
31#ifndef HAVE_STRLCPY 20#ifndef HAVE_STRLCPY
32 21
33#if defined(LIBC_SCCS) && !defined(lint) 22#if defined(LIBC_SCCS) && !defined(lint)
34static char *rcsid = "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $"; 23static char *rcsid = "$OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $";
35#endif /* LIBC_SCCS and not lint */ 24#endif /* LIBC_SCCS and not lint */
36 25
37#include <sys/types.h> 26#include <sys/types.h>
@@ -44,10 +33,7 @@ static char *rcsid = "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp
44 * Returns strlen(src); if retval >= siz, truncation occurred. 33 * Returns strlen(src); if retval >= siz, truncation occurred.
45 */ 34 */
46size_t 35size_t
47strlcpy(dst, src, siz) 36strlcpy(char *dst, const char *src, size_t siz)
48 char *dst;
49 const char *src;
50 size_t siz;
51{ 37{
52 register char *d = dst; 38 register char *d = dst;
53 register const char *s = src; 39 register const char *s = src;
diff --git a/openbsd-compat/vis.c b/openbsd-compat/vis.c
index fc5741390..0d15886f0 100644
--- a/openbsd-compat/vis.c
+++ b/openbsd-compat/vis.c
@@ -34,7 +34,7 @@
34#if !defined(HAVE_STRNVIS) 34#if !defined(HAVE_STRNVIS)
35 35
36#if defined(LIBC_SCCS) && !defined(lint) 36#if defined(LIBC_SCCS) && !defined(lint)
37static char rcsid[] = "$OpenBSD: vis.c,v 1.8 2002/02/19 19:39:36 millert Exp $"; 37static char rcsid[] = "$OpenBSD: vis.c,v 1.11 2003/05/14 05:16:43 pjanzen Exp $";
38#endif /* LIBC_SCCS and not lint */ 38#endif /* LIBC_SCCS and not lint */
39 39
40#include <ctype.h> 40#include <ctype.h>
@@ -47,8 +47,9 @@ static char rcsid[] = "$OpenBSD: vis.c,v 1.8 2002/02/19 19:39:36 millert Exp $";
47 ((flag & VIS_SP) == 0 && (c) == ' ') || \ 47 ((flag & VIS_SP) == 0 && (c) == ' ') || \
48 ((flag & VIS_TAB) == 0 && (c) == '\t') || \ 48 ((flag & VIS_TAB) == 0 && (c) == '\t') || \
49 ((flag & VIS_NL) == 0 && (c) == '\n') || \ 49 ((flag & VIS_NL) == 0 && (c) == '\n') || \
50 ((flag & VIS_SAFE) && \ 50 ((flag & VIS_SAFE) && ((c) == '\b' || \
51 ((c) == '\b' || (c) == '\007' || (c) == '\r'))) 51 (c) == '\007' || (c) == '\r' || \
52 isgraph((u_char)(c)))))
52 53
53/* 54/*
54 * vis - visually encode characters 55 * vis - visually encode characters
@@ -169,16 +170,20 @@ strvis(dst, src, flag)
169 170
170int 171int
171strnvis(dst, src, siz, flag) 172strnvis(dst, src, siz, flag)
172 register char *dst; 173 char *dst;
173 register const char *src; 174 const char *src;
174 size_t siz; 175 size_t siz;
175 int flag; 176 int flag;
176{ 177{
177 register char c; 178 char c;
178 char *start, *end; 179 char *start, *end;
180 char tbuf[5];
181 int i;
179 182
183 i = 0;
180 for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) { 184 for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) {
181 if (isvisible(c)) { 185 if (isvisible(c)) {
186 i = 1;
182 *dst++ = c; 187 *dst++ = c;
183 if (c == '\\' && (flag & VIS_NOSLASH) == 0) { 188 if (c == '\\' && (flag & VIS_NOSLASH) == 0) {
184 /* need space for the extra '\\' */ 189 /* need space for the extra '\\' */
@@ -186,22 +191,25 @@ strnvis(dst, src, siz, flag)
186 *dst++ = '\\'; 191 *dst++ = '\\';
187 else { 192 else {
188 dst--; 193 dst--;
194 i = 2;
189 break; 195 break;
190 } 196 }
191 } 197 }
192 src++; 198 src++;
193 } else { 199 } else {
194 /* vis(3) requires up to 4 chars */ 200 i = vis(tbuf, c, flag, *++src) - tbuf;
195 if (dst + 3 < end) 201 if (dst + i <= end) {
196 dst = vis(dst, c, flag, *++src); 202 memcpy(dst, tbuf, i);
197 else 203 dst += i;
204 } else {
205 src--;
198 break; 206 break;
207 }
199 } 208 }
200 } 209 }
201 *dst = '\0'; 210 if (siz > 0)
202 if (dst >= end) { 211 *dst = '\0';
203 char tbuf[5]; 212 if (dst + i > end) {
204
205 /* adjust return value for truncation */ 213 /* adjust return value for truncation */
206 while ((c = *src)) 214 while ((c = *src))
207 dst += vis(tbuf, c, flag, *++src) - tbuf; 215 dst += vis(tbuf, c, flag, *++src) - tbuf;