- (djm) Sync openbsd-compat/ with OpenBSD CVS head

This commit is contained in:
Damien Miller 2003-05-18 22:24:09 +10:00
parent 0b8e9006d8
commit e323df6c48
5 changed files with 71 additions and 85 deletions

View File

@ -16,6 +16,7 @@
ok djm@ ok djm@
- (djm) Remove IPv4 by default hack now that we can specify AF in config - (djm) Remove IPv4 by default hack now that we can specify AF in config
- (djm) Tidy and trim TODO - (djm) Tidy and trim TODO
- (djm) Sync openbsd-compat/ with OpenBSD CVS head
20030517 20030517
- (bal) strcat -> strlcat on openbsd-compat/realpath.c (rev 1.8 OpenBSD) - (bal) strcat -> strlcat on openbsd-compat/realpath.c (rev 1.8 OpenBSD)
@ -1571,4 +1572,4 @@
save auth method before monitor_reset_key_state(); bugzilla bug #284; save auth method before monitor_reset_key_state(); bugzilla bug #284;
ok provos@ ok provos@
$Id: ChangeLog,v 1.2737 2003/05/18 11:45:26 djm Exp $ $Id: ChangeLog,v 1.2738 2003/05/18 12:24:09 djm Exp $

View File

@ -1,4 +1,4 @@
/* $OpenBSD: getrrsetbyname.c,v 1.4 2001/08/16 18:16:43 ho Exp $ */ /* $OpenBSD: getrrsetbyname.c,v 1.7 2003/03/07 07:34:14 itojun Exp $ */
/* /*
* Copyright (c) 2001 Jakob Schlyter. All rights reserved. * Copyright (c) 2001 Jakob Schlyter. All rights reserved.
@ -49,6 +49,8 @@
#include "getrrsetbyname.h" #include "getrrsetbyname.h"
/* #include "thread_private.h" */
#define ANSWER_BUFFER_SIZE 1024*64 #define ANSWER_BUFFER_SIZE 1024*64
struct dns_query { struct dns_query {
@ -76,10 +78,10 @@ struct dns_response {
struct dns_rr *additional; struct dns_rr *additional;
}; };
static struct dns_response *parse_dns_response(const char *, int); static struct dns_response *parse_dns_response(const u_char *, int);
static struct dns_query *parse_dns_qsection(const char *, int, const char **, static struct dns_query *parse_dns_qsection(const u_char *, int,
int); const u_char **, int);
static struct dns_rr *parse_dns_rrsection(const char *, int, const char **, static struct dns_rr *parse_dns_rrsection(const u_char *, int, const u_char **,
int); int);
static void free_dns_query(struct dns_query *); static void free_dns_query(struct dns_query *);
@ -153,13 +155,15 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
unsigned int rdtype, unsigned int flags, unsigned int rdtype, unsigned int flags,
struct rrsetinfo **res) struct rrsetinfo **res)
{ {
struct __res_state *_resp = &_res;
int result; int result;
struct rrsetinfo *rrset = NULL; struct rrsetinfo *rrset = NULL;
struct dns_response *response; struct dns_response *response;
struct dns_rr *rr; struct dns_rr *rr;
struct rdatainfo *rdata; struct rdatainfo *rdata;
unsigned int length, index_ans, index_sig; int length;
char answer[ANSWER_BUFFER_SIZE]; unsigned int index_ans, index_sig;
u_char answer[ANSWER_BUFFER_SIZE];
/* check for invalid class and type */ /* check for invalid class and type */
if (rdclass > 0xffff || rdtype > 0xffff) { if (rdclass > 0xffff || rdtype > 0xffff) {
@ -180,23 +184,24 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
} }
/* initialize resolver */ /* initialize resolver */
if ((_res.options & RES_INIT) == 0 && res_init() == -1) { if ((_resp->options & RES_INIT) == 0 && res_init() == -1) {
result = ERRSET_FAIL; result = ERRSET_FAIL;
goto fail; goto fail;
} }
#ifdef DEBUG #ifdef DEBUG
_res.options |= RES_DEBUG; _resp->options |= RES_DEBUG;
#endif /* DEBUG */ #endif /* DEBUG */
#ifdef RES_USE_DNSSEC #ifdef RES_USE_DNSSEC
/* turn on DNSSEC if EDNS0 is configured */ /* turn on DNSSEC if EDNS0 is configured */
if (_res.options & RES_USE_EDNS0) if (_resp->options & RES_USE_EDNS0)
_res.options |= RES_USE_DNSSEC; _resp->options |= RES_USE_DNSSEC;
#endif /* RES_USE_DNSEC */ #endif /* RES_USE_DNSEC */
/* make query */ /* make query */
length = res_query(hostname, rdclass, rdtype, answer, sizeof(answer)); length = res_query(hostname, (signed int) rdclass, (signed int) rdtype,
answer, sizeof(answer));
if (length < 0) { if (length < 0) {
switch(h_errno) { switch(h_errno) {
case HOST_NOT_FOUND: case HOST_NOT_FOUND:
@ -338,10 +343,10 @@ freerrset(struct rrsetinfo *rrset)
* DNS response parsing routines * DNS response parsing routines
*/ */
static struct dns_response * static struct dns_response *
parse_dns_response(const char *answer, int size) parse_dns_response(const u_char *answer, int size)
{ {
struct dns_response *resp; struct dns_response *resp;
const char *cp; const u_char *cp;
/* allocate memory for the response */ /* allocate memory for the response */
resp = calloc(1, sizeof(*resp)); resp = calloc(1, sizeof(*resp));
@ -403,7 +408,7 @@ parse_dns_response(const char *answer, int size)
} }
static struct dns_query * static struct dns_query *
parse_dns_qsection(const char *answer, int size, const char **cp, int count) parse_dns_qsection(const u_char *answer, int size, const u_char **cp, int count)
{ {
struct dns_query *head, *curr, *prev; struct dns_query *head, *curr, *prev;
int i, length; int i, length;
@ -449,7 +454,7 @@ parse_dns_qsection(const char *answer, int size, const char **cp, int count)
} }
static struct dns_rr * static struct dns_rr *
parse_dns_rrsection(const char *answer, int size, const char **cp, int count) parse_dns_rrsection(const u_char *answer, int size, const u_char **cp, int count)
{ {
struct dns_rr *head, *curr, *prev; struct dns_rr *head, *curr, *prev;
int i, length; int i, length;

View File

@ -1,37 +1,26 @@
/* $OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $ */ /* $OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp $ */
/* /*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Permission to use, copy, modify, and distribute this software for any
* modification, are permitted provided that the following conditions * purpose with or without fee is hereby granted, provided that the above
* are met: * copyright notice and this permission notice appear in all copies.
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "includes.h" #include "includes.h"
#ifndef HAVE_STRLCAT #ifndef HAVE_STRLCAT
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $"; static char *rcsid = "$OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <sys/types.h> #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
* If retval >= siz, truncation occurred. * If retval >= siz, truncation occurred.
*/ */
size_t size_t
strlcat(dst, src, siz) strlcat(char *dst, const char *src, size_t siz)
char *dst;
const char *src;
size_t siz;
{ {
register char *d = dst; register char *d = dst;
register const char *s = src; register const char *s = src;

View File

@ -1,37 +1,26 @@
/* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */ /* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */
/* /*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Permission to use, copy, modify, and distribute this software for any
* modification, are permitted provided that the following conditions * purpose with or without fee is hereby granted, provided that the above
* are met: * copyright notice and this permission notice appear in all copies.
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "includes.h" #include "includes.h"
#ifndef HAVE_STRLCPY #ifndef HAVE_STRLCPY
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $"; static char *rcsid = "$OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <sys/types.h> #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
* Returns strlen(src); if retval >= siz, truncation occurred. * Returns strlen(src); if retval >= siz, truncation occurred.
*/ */
size_t size_t
strlcpy(dst, src, siz) strlcpy(char *dst, const char *src, size_t siz)
char *dst;
const char *src;
size_t siz;
{ {
register char *d = dst; register char *d = dst;
register const char *s = src; register const char *s = src;

View File

@ -34,7 +34,7 @@
#if !defined(HAVE_STRNVIS) #if !defined(HAVE_STRNVIS)
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: vis.c,v 1.8 2002/02/19 19:39:36 millert Exp $"; static char rcsid[] = "$OpenBSD: vis.c,v 1.11 2003/05/14 05:16:43 pjanzen Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <ctype.h> #include <ctype.h>
@ -47,8 +47,9 @@ static char rcsid[] = "$OpenBSD: vis.c,v 1.8 2002/02/19 19:39:36 millert Exp $";
((flag & VIS_SP) == 0 && (c) == ' ') || \ ((flag & VIS_SP) == 0 && (c) == ' ') || \
((flag & VIS_TAB) == 0 && (c) == '\t') || \ ((flag & VIS_TAB) == 0 && (c) == '\t') || \
((flag & VIS_NL) == 0 && (c) == '\n') || \ ((flag & VIS_NL) == 0 && (c) == '\n') || \
((flag & VIS_SAFE) && \ ((flag & VIS_SAFE) && ((c) == '\b' || \
((c) == '\b' || (c) == '\007' || (c) == '\r'))) (c) == '\007' || (c) == '\r' || \
isgraph((u_char)(c)))))
/* /*
* vis - visually encode characters * vis - visually encode characters
@ -169,16 +170,20 @@ strvis(dst, src, flag)
int int
strnvis(dst, src, siz, flag) strnvis(dst, src, siz, flag)
register char *dst; char *dst;
register const char *src; const char *src;
size_t siz; size_t siz;
int flag; int flag;
{ {
register char c; char c;
char *start, *end; char *start, *end;
char tbuf[5];
int i;
i = 0;
for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) { for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) {
if (isvisible(c)) { if (isvisible(c)) {
i = 1;
*dst++ = c; *dst++ = c;
if (c == '\\' && (flag & VIS_NOSLASH) == 0) { if (c == '\\' && (flag & VIS_NOSLASH) == 0) {
/* need space for the extra '\\' */ /* need space for the extra '\\' */
@ -186,22 +191,25 @@ strnvis(dst, src, siz, flag)
*dst++ = '\\'; *dst++ = '\\';
else { else {
dst--; dst--;
i = 2;
break; break;
} }
} }
src++; src++;
} else { } else {
/* vis(3) requires up to 4 chars */ i = vis(tbuf, c, flag, *++src) - tbuf;
if (dst + 3 < end) if (dst + i <= end) {
dst = vis(dst, c, flag, *++src); memcpy(dst, tbuf, i);
else dst += i;
} else {
src--;
break; break;
} }
} }
}
if (siz > 0)
*dst = '\0'; *dst = '\0';
if (dst >= end) { if (dst + i > end) {
char tbuf[5];
/* adjust return value for truncation */ /* adjust return value for truncation */
while ((c = *src)) while ((c = *src))
dst += vis(tbuf, c, flag, *++src) - tbuf; dst += vis(tbuf, c, flag, *++src) - tbuf;