diff -pruN /home/reed/src/isc/libbind/libbind/nameser/ns_date.c /usr/src/lib/libc/nameser/ns_date.c --- /home/reed/src/isc/libbind/libbind/nameser/ns_date.c 2005-04-26 23:56:39.000000000 -0500 +++ /usr/src/lib/libc/nameser/ns_date.c 1969-12-31 18:00:00.000000000 -0600 @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef lint -static const char rcsid[] = "$Id: ns_date.c,v 1.6 2005/04/27 04:56:39 sra Exp $"; -#endif - -/* Import. */ - -#include "port_before.h" - -#include - -#include -#include -#include -#include -#include - -#include "port_after.h" - -#ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) -#else -# define SPRINTF(x) ((size_t)sprintf x) -#endif - -/* Forward. */ - -static int datepart(const char *, int, int, int, int *); - -/* Public. */ - -/*% - * Convert a date in ASCII into the number of seconds since - * 1 January 1970 (GMT assumed). Format is yyyymmddhhmmss, all - * digits required, no spaces allowed. - */ - -u_int32_t -ns_datetosecs(const char *cp, int *errp) { - struct tm time; - u_int32_t result; - int mdays, i; - static const int days_per_month[12] = - {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - - if (strlen(cp) != 14U) { - *errp = 1; - return (0); - } - *errp = 0; - - memset(&time, 0, sizeof time); - time.tm_year = datepart(cp + 0, 4, 1990, 9999, errp) - 1900; - time.tm_mon = datepart(cp + 4, 2, 01, 12, errp) - 1; - time.tm_mday = datepart(cp + 6, 2, 01, 31, errp); - time.tm_hour = datepart(cp + 8, 2, 00, 23, errp); - time.tm_min = datepart(cp + 10, 2, 00, 59, errp); - time.tm_sec = datepart(cp + 12, 2, 00, 59, errp); - if (*errp) /*%< Any parse errors? */ - return (0); - - /* - * OK, now because timegm() is not available in all environments, - * we will do it by hand. Roll up sleeves, curse the gods, begin! - */ - -#define SECS_PER_DAY ((u_int32_t)24*60*60) -#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) - - result = time.tm_sec; /*%< Seconds */ - result += time.tm_min * 60; /*%< Minutes */ - result += time.tm_hour * (60*60); /*%< Hours */ - result += (time.tm_mday - 1) * SECS_PER_DAY; /*%< Days */ - /* Months are trickier. Look without leaping, then leap */ - mdays = 0; - for (i = 0; i < time.tm_mon; i++) - mdays += days_per_month[i]; - result += mdays * SECS_PER_DAY; /*%< Months */ - if (time.tm_mon > 1 && isleap(1900+time.tm_year)) - result += SECS_PER_DAY; /*%< Add leapday for this year */ - /* First figure years without leapdays, then add them in. */ - /* The loop is slow, FIXME, but simple and accurate. */ - result += (time.tm_year - 70) * (SECS_PER_DAY*365); /*%< Years */ - for (i = 70; i < time.tm_year; i++) - if (isleap(1900+i)) - result += SECS_PER_DAY; /*%< Add leapday for prev year */ - return (result); -} - -/* Private. */ - -/*% - * Parse part of a date. Set error flag if any error. - * Don't reset the flag if there is no error. - */ -static int -datepart(const char *buf, int size, int min, int max, int *errp) { - int result = 0; - int i; - - for (i = 0; i < size; i++) { - if (!isdigit((unsigned char)(buf[i]))) - *errp = 1; - result = (result * 10) + buf[i] - '0'; - } - if (result < min) - *errp = 1; - if (result > max) - *errp = 1; - return (result); -} - -/*! \file */ diff -pruN /home/reed/src/isc/libbind/libbind/nameser/ns_name.c /usr/src/lib/libc/nameser/ns_name.c --- /home/reed/src/isc/libbind/libbind/nameser/ns_name.c 2009-10-20 13:36:49.000000000 -0500 +++ /usr/src/lib/libc/nameser/ns_name.c 2013-06-05 09:26:12.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: ns_name.c,v 1.9 2012/03/13 21:13:39 christos Exp $ */ + /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. @@ -15,8 +17,13 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #ifndef lint -static const char rcsid[] = "$Id: ns_name.c,v 1.12 2009/07/16 04:11:46 marka Exp $"; +#ifdef notdef +static const char rcsid[] = "Id: ns_name.c,v 1.11 2009/01/23 19:59:16 each Exp"; +#else +__RCSID("$NetBSD: ns_name.c,v 1.9 2012/03/13 21:13:39 christos Exp $"); +#endif #endif #include "port_before.h" @@ -26,6 +33,7 @@ static const char rcsid[] = "$Id: ns_nam #include #include +#include #include #include #include @@ -36,9 +44,9 @@ static const char rcsid[] = "$Id: ns_nam #include "port_after.h" #ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) +# define SPRINTF(x) ((int)strlen(sprintf/**/x)) #else -# define SPRINTF(x) ((size_t)sprintf x) +# define SPRINTF(x) (sprintf x) #endif #define NS_TYPE_ELT 0x40 /*%< EDNS0 extended label type */ @@ -106,14 +114,6 @@ ns_name_ntop(const u_char *src, char *ds dn = dst; eom = dst + dstsiz; - /* - * Do we have sane arguements? - */ - if (dn >= eom) { - errno = EMSGSIZE; - return (-1); - } - while ((n = *cp++) != 0) { if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { /* Some kind of compression pointer. */ @@ -151,7 +151,7 @@ ns_name_ntop(const u_char *src, char *ds dn += m; continue; } - for ((void)NULL; l > 0; l--) { + for (; l > 0; l--) { c = *cp++; if (special(c)) { if (dn + 1 >= eom) { @@ -190,7 +190,8 @@ ns_name_ntop(const u_char *src, char *ds return (-1); } *dn++ = '\0'; - return (dn - dst); + _DIAGASSERT(__type_fit(int, dn - dst)); + return (int)(dn - dst); } /*% @@ -257,19 +258,19 @@ ns_name_pton2(const char *src, u_char *d continue; } else if ((cp = strchr(digits, c)) != NULL) { - n = (cp - digits) * 100; + n = (int)(cp - digits) * 100; if ((c = *src++) == 0 || (cp = strchr(digits, c)) == NULL) { errno = EMSGSIZE; return (-1); } - n += (cp - digits) * 10; + n += (int)(cp - digits) * 10; if ((c = *src++) == 0 || (cp = strchr(digits, c)) == NULL) { errno = EMSGSIZE; return (-1); } - n += (cp - digits); + n += (int)(cp - digits); if (n > 255) { errno = EMSGSIZE; return (-1); @@ -281,7 +282,7 @@ ns_name_pton2(const char *src, u_char *d escaped = 1; continue; } else if (c == '.') { - c = (bp - label - 1); + c = (int)(bp - label - 1); if ((c & NS_CMPRSFLGS) != 0) { /*%< Label too big. */ errno = EMSGSIZE; return (-1); @@ -321,7 +322,7 @@ ns_name_pton2(const char *src, u_char *d } *bp++ = (u_char)c; } - c = (bp - label - 1); + c = (int)(bp - label - 1); if ((c & NS_CMPRSFLGS) != 0) { /*%< Label too big. */ errno = EMSGSIZE; return (-1); @@ -390,7 +391,7 @@ ns_name_ntol(const u_char *src, u_char * errno = EMSGSIZE; return (-1); } - for ((void)NULL; l > 0; l--) { + for (; l > 0; l--) { c = *cp++; if (isascii(c) && isupper(c)) *dn++ = tolower(c); @@ -399,7 +400,8 @@ ns_name_ntol(const u_char *src, u_char * } } *dn++ = '\0'; - return (dn - dst); + _DIAGASSERT(__type_fit(int, dn - dst)); + return (int)(dn - dst); } /*% @@ -457,7 +459,7 @@ ns_name_unpack2(const u_char *msg, const } checked += l + 1; *dstp++ = n; - memcpy(dstp, srcp, l); + memcpy(dstp, srcp, (size_t)l); dstp += l; srcp += l; break; @@ -467,8 +469,10 @@ ns_name_unpack2(const u_char *msg, const errno = EMSGSIZE; return (-1); } - if (len < 0) - len = srcp - src + 1; + if (len < 0) { + _DIAGASSERT(__type_fit(int, srcp - src + 1)); + len = (int)(srcp - src + 1); + } srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff)); if (srcp < msg || srcp >= eom) { /*%< Out of range. */ errno = EMSGSIZE; @@ -494,9 +498,11 @@ ns_name_unpack2(const u_char *msg, const *dstp++ = 0; if (dstlen != NULL) *dstlen = dstp - dst; - if (len < 0) - len = srcp - src; - return (len); + if (len < 0) { + _DIAGASSERT(__type_fit(int, srcp - src)); + len = (int)(srcp - src); + } + return len; } /*% @@ -534,7 +540,7 @@ ns_name_pack(const u_char *src, u_char * if (dnptrs != NULL) { if ((msg = *dnptrs++) != NULL) { for (cpp = dnptrs; *cpp != NULL; cpp++) - (void)NULL; + continue; lpp = cpp; /*%< end of list to search */ } } else @@ -574,9 +580,10 @@ ns_name_pack(const u_char *src, u_char * if (dstp + 1 >= eob) { goto cleanup; } - *dstp++ = (l >> 8) | NS_CMPRSFLGS; + *dstp++ = ((u_int32_t)l >> 8) | NS_CMPRSFLGS; *dstp++ = l % 256; - return (dstp - dst); + _DIAGASSERT(__type_fit(int, dstp - dst)); + return (int)(dstp - dst); } /* Not found, save it. */ if (lastdnptr != NULL && cpp < lastdnptr - 1 && @@ -595,7 +602,7 @@ ns_name_pack(const u_char *src, u_char * if (dstp + 1 + n >= eob) { goto cleanup; } - memcpy(dstp, srcp, n + 1); + memcpy(dstp, srcp, (size_t)(n + 1)); srcp += n + 1; dstp += n + 1; } while (n != 0); @@ -607,7 +614,8 @@ cleanup: errno = EMSGSIZE; return (-1); } - return (dstp - dst); + _DIAGASSERT(__type_fit(int, dstp - dst)); + return (int)(dstp - dst); } /*% @@ -656,7 +664,7 @@ ns_name_compress(const char *src, u_char if (ns_name_pton(src, tmp, sizeof tmp) == -1) return (-1); - return (ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr)); + return (ns_name_pack(tmp, dst, (int)dstsiz, dnptrs, lastdnptr)); } /*% @@ -761,7 +769,8 @@ ns_name_eq(ns_nname_ct a, size_t as, ns_ return (-1); } if (ac != bc || strncasecmp((const char *) ++a, - (const char *) ++b, ac) != 0) + (const char *) ++b, + (size_t)ac) != 0) return (0); a += ac, b += bc; } @@ -780,7 +789,7 @@ ns_name_owned(ns_namemap_ct a, int an, n while (bn > 0) { if (a->len != b->len || strncasecmp((const char *) a->base, - (const char *) b->base, a->len) != 0) + (const char *) b->base, (size_t)a->len) != 0) return (0); a++, an--; b++, bn--; @@ -955,13 +964,16 @@ dn_find(const u_char *domain, const u_ch if (n != *dn++) goto next; - for ((void)NULL; n > 0; n--) + for (; n > 0; n--) if (mklower(*dn++) != mklower(*cp++)) goto next; /* Is next root for both ? */ - if (*dn == '\0' && *cp == '\0') - return (sp - msg); + if (*dn == '\0' && *cp == '\0') { + _DIAGASSERT(__type_fit(int, + sp - msg)); + return (int)(sp - msg); + } if (*dn) continue; goto next; @@ -992,7 +1004,7 @@ decode_bitstring(const unsigned char **c if ((blen = (*cp & 0xff)) == 0) blen = 256; plen = (blen + 3) / 4; - plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1); + plen += (int)sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1); if (dn + plen >= eom) return (-1); @@ -1016,7 +1028,7 @@ decode_bitstring(const unsigned char **c } else if (b > 0) { tc = *cp++; i = SPRINTF((dn, "%1x", - ((tc >> 4) & 0x0f) & (0x0f << (4 - b)))); + (((u_int32_t)tc >> 4) & 0x0f) & (0x0f << (4 - b)))); if (i < 0) return (-1); dn += i; @@ -1027,7 +1039,8 @@ decode_bitstring(const unsigned char **c dn += i; *cpp = cp; - return (dn - beg); + _DIAGASSERT(__type_fit(int, dn - beg)); + return (int)(dn - beg); } static int diff -pruN /home/reed/src/isc/libbind/libbind/nameser/ns_netint.c /usr/src/lib/libc/nameser/ns_netint.c --- /home/reed/src/isc/libbind/libbind/nameser/ns_netint.c 2005-04-26 23:56:40.000000000 -0500 +++ /usr/src/lib/libc/nameser/ns_netint.c 2013-06-05 09:26:12.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: ns_netint.c,v 1.7 2012/03/13 21:13:39 christos Exp $ */ + /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. @@ -15,8 +17,13 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #ifndef lint -static const char rcsid[] = "$Id: ns_netint.c,v 1.3 2005/04/27 04:56:40 sra Exp $"; +#ifdef notdef +static const char rcsid[] = "Id: ns_netint.c,v 1.3 2005/04/27 04:56:40 sra Exp"; +#else +__RCSID("$NetBSD: ns_netint.c,v 1.7 2012/03/13 21:13:39 christos Exp $"); +#endif #endif /* Import. */ @@ -29,29 +36,29 @@ static const char rcsid[] = "$Id: ns_net /* Public. */ -u_int +uint16_t ns_get16(const u_char *src) { - u_int dst; + uint16_t dst; NS_GET16(dst, src); - return (dst); + return dst; } -u_long +uint32_t ns_get32(const u_char *src) { - u_long dst; + u_int32_t dst; NS_GET32(dst, src); - return (dst); + return dst; } void -ns_put16(u_int src, u_char *dst) { +ns_put16(uint16_t src, u_char *dst) { NS_PUT16(src, dst); } void -ns_put32(u_long src, u_char *dst) { +ns_put32(uint32_t src, u_char *dst) { NS_PUT32(src, dst); } diff -pruN /home/reed/src/isc/libbind/libbind/nameser/ns_newmsg.c /usr/src/lib/libc/nameser/ns_newmsg.c --- /home/reed/src/isc/libbind/libbind/nameser/ns_newmsg.c 2009-04-15 17:40:02.000000000 -0500 +++ /usr/src/lib/libc/nameser/ns_newmsg.c 1969-12-31 18:00:00.000000000 -0600 @@ -1,263 +0,0 @@ -/* - * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef lint -static const char rcsid[] = "$Id: ns_newmsg.c,v 1.3 2009/02/26 10:48:57 marka Exp $"; -#endif - -#include - -#include -#include -#include - -static int rdcpy(ns_newmsg *, ns_type, const u_char *, size_t); - -/* Initialize a "newmsg" object to empty. - */ -int -ns_newmsg_init(u_char *buffer, size_t bufsiz, ns_newmsg *handle) { - ns_msg *msg = &handle->msg; - - memset(handle, 0, sizeof *handle); - msg->_msg = buffer; - msg->_eom = buffer + bufsiz; - msg->_sect = ns_s_qd; - msg->_rrnum = 0; - msg->_msg_ptr = buffer + NS_HFIXEDSZ; - handle->dnptrs[0] = msg->_msg; - handle->dnptrs[1] = NULL; - handle->lastdnptr = &handle->dnptrs[sizeof handle->dnptrs / - sizeof handle->dnptrs[0] - 1]; - return (0); -} - -/* Initialize a "newmsg" object by copying an existing parsed message. - */ -int -ns_newmsg_copy(ns_newmsg *handle, ns_msg *msg) { - ns_flag flag; - ns_sect sect; - - ns_newmsg_id(handle, ns_msg_id(*msg)); - for (flag = ns_f_qr; flag < ns_f_max; flag++) - ns_newmsg_flag(handle, flag, ns_msg_getflag(*msg, flag)); - for (sect = ns_s_qd; sect < ns_s_max; sect++) { - int i, count; - - count = ns_msg_count(*msg, sect); - for (i = 0; i < count; i++) { - ns_rr2 rr; - int x; - - if (ns_parserr2(msg, sect, i, &rr) < 0) - return (-1); - if (sect == ns_s_qd) - x = ns_newmsg_q(handle, - ns_rr_nname(rr), - ns_rr_type(rr), - ns_rr_class(rr)); - else - x = ns_newmsg_rr(handle, sect, - ns_rr_nname(rr), - ns_rr_type(rr), - ns_rr_class(rr), - ns_rr_ttl(rr), - ns_rr_rdlen(rr), - ns_rr_rdata(rr)); - if (x < 0) - return (-1); - } - } - return (0); -} - -/* Set the message-ID in a "newmsg" object. - */ -void -ns_newmsg_id(ns_newmsg *handle, u_int16_t id) { - ns_msg *msg = &handle->msg; - - msg->_id = id; -} - -/* Set a flag (including rcode or opcode) in a "newmsg" object. - */ -void -ns_newmsg_flag(ns_newmsg *handle, ns_flag flag, u_int value) { - extern struct _ns_flagdata _ns_flagdata[16]; - struct _ns_flagdata *fd = &_ns_flagdata[flag]; - ns_msg *msg = &handle->msg; - - assert(flag < ns_f_max); - msg->_flags &= (~fd->mask); - msg->_flags |= (value << fd->shift); -} - -/* Add a question (or zone, if it's an update) to a "newmsg" object. - */ -int -ns_newmsg_q(ns_newmsg *handle, ns_nname_ct qname, - ns_type qtype, ns_class qclass) -{ - ns_msg *msg = &handle->msg; - u_char *t; - int n; - - if (msg->_sect != ns_s_qd) { - errno = ENODEV; - return (-1); - } - t = (u_char *) (unsigned long) msg->_msg_ptr; - if (msg->_rrnum == 0) - msg->_sections[ns_s_qd] = t; - n = ns_name_pack(qname, t, msg->_eom - t, - handle->dnptrs, handle->lastdnptr); - if (n < 0) - return (-1); - t += n; - if (t + QFIXEDSZ >= msg->_eom) { - errno = EMSGSIZE; - return (-1); - } - NS_PUT16(qtype, t); - NS_PUT16(qclass, t); - msg->_msg_ptr = t; - msg->_counts[ns_s_qd] = ++msg->_rrnum; - return (0); -} - -/* Add an RR to a "newmsg" object. - */ -int -ns_newmsg_rr(ns_newmsg *handle, ns_sect sect, - ns_nname_ct name, ns_type type, - ns_class rr_class, u_int32_t ttl, - u_int16_t rdlen, const u_char *rdata) -{ - ns_msg *msg = &handle->msg; - u_char *t; - int n; - - if (sect < msg->_sect) { - errno = ENODEV; - return (-1); - } - t = (u_char *) (unsigned long) msg->_msg_ptr; - if (sect > msg->_sect) { - msg->_sect = sect; - msg->_sections[sect] = t; - msg->_rrnum = 0; - } - n = ns_name_pack(name, t, msg->_eom - t, - handle->dnptrs, handle->lastdnptr); - if (n < 0) - return (-1); - t += n; - if (t + RRFIXEDSZ + rdlen >= msg->_eom) { - errno = EMSGSIZE; - return (-1); - } - NS_PUT16(type, t); - NS_PUT16(rr_class, t); - NS_PUT32(ttl, t); - msg->_msg_ptr = t; - if (rdcpy(handle, type, rdata, rdlen) < 0) - return (-1); - msg->_counts[sect] = ++msg->_rrnum; - return (0); -} - -/* Complete a "newmsg" object and return its size for use in write(). - * (Note: the "newmsg" object is also made ready for ns_parserr() etc.) - */ -size_t -ns_newmsg_done(ns_newmsg *handle) { - ns_msg *msg = &handle->msg; - ns_sect sect; - u_char *t; - - t = (u_char *) (unsigned long) msg->_msg; - NS_PUT16(msg->_id, t); - NS_PUT16(msg->_flags, t); - for (sect = 0; sect < ns_s_max; sect++) - NS_PUT16(msg->_counts[sect], t); - msg->_eom = msg->_msg_ptr; - msg->_sect = ns_s_max; - msg->_rrnum = -1; - msg->_msg_ptr = NULL; - return (msg->_eom - msg->_msg); -} - -/* Private. */ - -/* Copy an RDATA, using compression pointers where RFC1035 permits. - */ -static int -rdcpy(ns_newmsg *handle, ns_type type, const u_char *rdata, size_t rdlen) { - ns_msg *msg = &handle->msg; - u_char *p = (u_char *) (unsigned long) msg->_msg_ptr; - u_char *t = p + NS_INT16SZ; - u_char *s = t; - int n; - - switch (type) { - case ns_t_soa: - /* MNAME. */ - n = ns_name_pack(rdata, t, msg->_eom - t, - handle->dnptrs, handle->lastdnptr); - if (n < 0) - return (-1); - t += n; - if (ns_name_skip(&rdata, msg->_eom) < 0) - return (-1); - - /* ANAME. */ - n = ns_name_pack(rdata, t, msg->_eom - t, - handle->dnptrs, handle->lastdnptr); - if (n < 0) - return (-1); - t += n; - if (ns_name_skip(&rdata, msg->_eom) < 0) - return (-1); - - /* Serial, Refresh, Retry, Expiry, and Minimum. */ - if ((msg->_eom - t) < (NS_INT32SZ * 5)) { - errno = EMSGSIZE; - return (-1); - } - memcpy(t, rdata, NS_INT32SZ * 5); - t += (NS_INT32SZ * 5); - break; - case ns_t_ptr: - case ns_t_cname: - case ns_t_ns: - /* PTRDNAME, CNAME, or NSDNAME. */ - n = ns_name_pack(rdata, t, msg->_eom - t, - handle->dnptrs, handle->lastdnptr); - if (n < 0) - return (-1); - t += n; - break; - default: - memcpy(t, rdata, rdlen); - t += rdlen; - } - NS_PUT16(t - s, p); - msg->_msg_ptr = t; - return (0); -} - diff -pruN /home/reed/src/isc/libbind/libbind/nameser/ns_parse.c /usr/src/lib/libc/nameser/ns_parse.c --- /home/reed/src/isc/libbind/libbind/nameser/ns_parse.c 2009-01-29 12:26:42.000000000 -0600 +++ /usr/src/lib/libc/nameser/ns_parse.c 2013-06-05 09:26:12.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: ns_parse.c,v 1.9 2012/03/13 21:13:39 christos Exp $ */ + /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. @@ -15,8 +17,13 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #ifndef lint -static const char rcsid[] = "$Id: ns_parse.c,v 1.10 2009/01/23 19:59:16 each Exp $"; +#ifdef notdef +static const char rcsid[] = "Id: ns_parse.c,v 1.10 2009/01/23 19:59:16 each Exp"; +#else +__RCSID("$NetBSD: ns_parse.c,v 1.9 2012/03/13 21:13:39 christos Exp $"); +#endif #endif /* Import. */ @@ -28,6 +35,7 @@ static const char rcsid[] = "$Id: ns_par #include #include +#include #include #include #include @@ -41,7 +49,7 @@ static void setsection(ns_msg *msg, ns_s /* Macros. */ #if !defined(SOLARIS2) || defined(__COVERITY__) -#define RETERR(err) do { errno = (err); return (-1); } while (0) +#define RETERR(err) do { errno = (err); return (-1); } while (/*NOTREACHED*//*CONSTCOND*/0) #else #define RETERR(err) \ do { errno = (err); if (errno == errno) return (-1); } while (0) @@ -73,14 +81,14 @@ struct _ns_flagdata _ns_flagdata[16] = { }; int ns_msg_getflag(ns_msg handle, int flag) { - return(((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift); + return((u_int32_t)((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift); } int ns_skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) { const u_char *optr = ptr; - for ((void)NULL; count > 0; count--) { + for (; count > 0; count--) { int b, rdlength; b = dn_skipname(ptr, eom); @@ -97,7 +105,8 @@ ns_skiprr(const u_char *ptr, const u_cha } if (ptr > eom) RETERR(EMSGSIZE); - return (ptr - optr); + _DIAGASSERT(__type_fit(int, ptr - optr)); + return (int)(ptr - optr); } int @@ -205,7 +214,8 @@ ns_parserr2(ns_msg *handle, ns_sect sect int tmp; /* Make section right. */ - if ((tmp = section) < 0 || section >= ns_s_max) + tmp = section; + if (tmp < 0 || section >= ns_s_max) RETERR(ENODEV); if (section != handle->_sect) setsection(handle, section); diff -pruN /home/reed/src/isc/libbind/libbind/nameser/ns_print.c /usr/src/lib/libc/nameser/ns_print.c --- /home/reed/src/isc/libbind/libbind/nameser/ns_print.c 2009-04-15 17:40:02.000000000 -0500 +++ /usr/src/lib/libc/nameser/ns_print.c 2013-06-05 09:26:12.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: ns_print.c,v 1.11 2012/03/13 21:13:39 christos Exp $ */ + /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. @@ -15,8 +17,13 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #ifndef lint -static const char rcsid[] = "$Id: ns_print.c,v 1.12 2009/03/03 05:29:58 each Exp $"; +#ifdef notdef +static const char rcsid[] = "Id: ns_print.c,v 1.12 2009/03/03 05:29:58 each Exp"; +#else +__RCSID("$NetBSD: ns_print.c,v 1.11 2012/03/13 21:13:39 christos Exp $"); +#endif #endif /* Import. */ @@ -32,17 +39,19 @@ static const char rcsid[] = "$Id: ns_pri #include #include +#include #include #include +#include #include #include #include "port_after.h" #ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) +# define SPRINTF(x) ((int)strlen(sprintf/**/x)) #else -# define SPRINTF(x) ((size_t)sprintf x) +# define SPRINTF(x) (sprintf x) #endif /* Forward. */ @@ -65,7 +74,7 @@ static int addtab(size_t len, size_t tar do { \ if ((x) < 0) \ return (-1); \ - } while (0) + } while (/*CONSTCOND*/0) static const char base32hex[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV=0123456789abcdefghijklmnopqrstuv"; @@ -117,24 +126,24 @@ ns_sprintrrf(const u_char *msg, size_t m * Owner. */ if (name_ctx != NULL && ns_samename(name_ctx, name) == 1) { - T(addstr("\t\t\t", 3, &buf, &buflen)); + T(addstr("\t\t\t", (size_t)3, &buf, &buflen)); } else { - len = prune_origin(name, origin); + len = (int)prune_origin(name, origin); if (*name == '\0') { goto root; } else if (len == 0) { - T(addstr("@\t\t\t", 4, &buf, &buflen)); + T(addstr("@\t\t\t", (size_t)4, &buf, &buflen)); } else { - T(addstr(name, len, &buf, &buflen)); + T(addstr(name, (size_t)len, &buf, &buflen)); /* Origin not used or not root, and no trailing dot? */ if (((origin == NULL || origin[0] == '\0') || (origin[0] != '.' && origin[1] != '\0' && name[len] == '\0')) && name[len - 1] != '.') { root: - T(addstr(".", 1, &buf, &buflen)); + T(addstr(".", (size_t)1, &buf, &buflen)); len++; } - T(spaced = addtab(len, 24, spaced, &buf, &buflen)); + T(spaced = addtab((size_t)len, 24, spaced, &buf, &buflen)); } } @@ -142,10 +151,10 @@ ns_sprintrrf(const u_char *msg, size_t m * TTL, Class, Type. */ T(x = ns_format_ttl(ttl, buf, buflen)); - addlen(x, &buf, &buflen); + addlen((size_t)x, &buf, &buflen); len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type))); - T(addstr(tmp, len, &buf, &buflen)); - T(spaced = addtab(x + len, 16, spaced, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); + T(spaced = addtab((size_t)(x + len), (size_t)16, spaced, &buf, &buflen)); /* * RData. @@ -154,7 +163,7 @@ ns_sprintrrf(const u_char *msg, size_t m case ns_t_a: if (rdlen != (size_t)NS_INADDRSZ) goto formerr; - (void) inet_ntop(AF_INET, rdata, buf, buflen); + (void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); break; @@ -175,7 +184,7 @@ ns_sprintrrf(const u_char *msg, size_t m if (len == 0) goto formerr; rdata += len; - T(addstr(" ", 1, &buf, &buflen)); + T(addstr(" ", (size_t)1, &buf, &buflen)); /* Second word, optional in ISDN records. */ @@ -193,11 +202,11 @@ ns_sprintrrf(const u_char *msg, size_t m /* Server name. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); - T(addstr(" ", 1, &buf, &buflen)); + T(addstr(" ", (size_t)1, &buf, &buflen)); /* Administrator name. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); - T(addstr(" (\n", 3, &buf, &buflen)); + T(addstr(" (\n", (size_t)3, &buf, &buflen)); spaced = 0; if ((edata - rdata) != 5*NS_INT32SZ) @@ -205,48 +214,48 @@ ns_sprintrrf(const u_char *msg, size_t m /* Serial number. */ t = ns_get32(rdata); rdata += NS_INT32SZ; - T(addstr("\t\t\t\t\t", 5, &buf, &buflen)); + T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen)); len = SPRINTF((tmp, "%lu", t)); - T(addstr(tmp, len, &buf, &buflen)); - T(spaced = addtab(len, 16, spaced, &buf, &buflen)); - T(addstr("; serial\n", 9, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); + T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen)); + T(addstr("; serial\n", (size_t)9, &buf, &buflen)); spaced = 0; /* Refresh interval. */ t = ns_get32(rdata); rdata += NS_INT32SZ; - T(addstr("\t\t\t\t\t", 5, &buf, &buflen)); + T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen)); T(len = ns_format_ttl(t, buf, buflen)); - addlen(len, &buf, &buflen); - T(spaced = addtab(len, 16, spaced, &buf, &buflen)); - T(addstr("; refresh\n", 10, &buf, &buflen)); + addlen((size_t)len, &buf, &buflen); + T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen)); + T(addstr("; refresh\n", (size_t)10, &buf, &buflen)); spaced = 0; /* Retry interval. */ t = ns_get32(rdata); rdata += NS_INT32SZ; - T(addstr("\t\t\t\t\t", 5, &buf, &buflen)); + T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen)); T(len = ns_format_ttl(t, buf, buflen)); - addlen(len, &buf, &buflen); - T(spaced = addtab(len, 16, spaced, &buf, &buflen)); - T(addstr("; retry\n", 8, &buf, &buflen)); + addlen((size_t)len, &buf, &buflen); + T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen)); + T(addstr("; retry\n", (size_t)8, &buf, &buflen)); spaced = 0; /* Expiry. */ t = ns_get32(rdata); rdata += NS_INT32SZ; - T(addstr("\t\t\t\t\t", 5, &buf, &buflen)); + T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen)); T(len = ns_format_ttl(t, buf, buflen)); - addlen(len, &buf, &buflen); - T(spaced = addtab(len, 16, spaced, &buf, &buflen)); - T(addstr("; expiry\n", 9, &buf, &buflen)); + addlen((size_t)len, &buf, &buflen); + T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen)); + T(addstr("; expiry\n", (size_t)9, &buf, &buflen)); spaced = 0; /* Minimum TTL. */ t = ns_get32(rdata); rdata += NS_INT32SZ; - T(addstr("\t\t\t\t\t", 5, &buf, &buflen)); + T(addstr("\t\t\t\t\t", (size_t)5, &buf, &buflen)); T(len = ns_format_ttl(t, buf, buflen)); - addlen(len, &buf, &buflen); - T(addstr(" )", 2, &buf, &buflen)); - T(spaced = addtab(len, 16, spaced, &buf, &buflen)); - T(addstr("; minimum\n", 10, &buf, &buflen)); + addlen((size_t)len, &buf, &buflen); + T(addstr(" )", (size_t)2, &buf, &buflen)); + T(spaced = addtab((size_t)len, (size_t)16, spaced, &buf, &buflen)); + T(addstr("; minimum\n", (size_t)10, &buf, &buflen)); break; } @@ -264,7 +273,7 @@ ns_sprintrrf(const u_char *msg, size_t m t = ns_get16(rdata); rdata += NS_INT16SZ; len = SPRINTF((tmp, "%u ", t)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); /* Target. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); @@ -282,11 +291,11 @@ ns_sprintrrf(const u_char *msg, size_t m t = ns_get16(rdata); rdata += NS_INT16SZ; len = SPRINTF((tmp, "%u ", t)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); /* Name1. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); - T(addstr(" ", 1, &buf, &buflen)); + T(addstr(" ", (size_t)1, &buf, &buflen)); /* Name2. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); @@ -309,14 +318,14 @@ ns_sprintrrf(const u_char *msg, size_t m goto formerr; rdata += len; if (rdata < edata) - T(addstr(" ", 1, &buf, &buflen)); + T(addstr(" ", (size_t)1, &buf, &buflen)); } break; case ns_t_nsap: { char t[2+255*3]; - (void) inet_nsap_ntoa(rdlen, rdata, t); + (void) inet_nsap_ntoa((int)rdlen, rdata, t); T(addstr(t, strlen(t), &buf, &buflen)); break; } @@ -324,7 +333,7 @@ ns_sprintrrf(const u_char *msg, size_t m case ns_t_aaaa: if (rdlen != (size_t)NS_IN6ADDRSZ) goto formerr; - (void) inet_ntop(AF_INET6, rdata, buf, buflen); + (void) inet_ntop(AF_INET6, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); break; @@ -348,21 +357,21 @@ ns_sprintrrf(const u_char *msg, size_t m order = ns_get16(rdata); rdata += NS_INT16SZ; preference = ns_get16(rdata); rdata += NS_INT16SZ; len = SPRINTF((t, "%u %u ", order, preference)); - T(addstr(t, len, &buf, &buflen)); + T(addstr(t, (size_t)len, &buf, &buflen)); /* Flags. */ T(len = charstr(rdata, edata, &buf, &buflen)); if (len == 0) goto formerr; rdata += len; - T(addstr(" ", 1, &buf, &buflen)); + T(addstr(" ", (size_t)1, &buf, &buflen)); /* Service. */ T(len = charstr(rdata, edata, &buf, &buflen)); if (len == 0) goto formerr; rdata += len; - T(addstr(" ", 1, &buf, &buflen)); + T(addstr(" ", (size_t)1, &buf, &buflen)); /* Regexp. */ T(len = charstr(rdata, edata, &buf, &buflen)); @@ -371,7 +380,7 @@ ns_sprintrrf(const u_char *msg, size_t m if (len == 0) goto formerr; rdata += len; - T(addstr(" ", 1, &buf, &buflen)); + T(addstr(" ", (size_t)1, &buf, &buflen)); /* Server. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); @@ -390,7 +399,7 @@ ns_sprintrrf(const u_char *msg, size_t m weight = ns_get16(rdata); rdata += NS_INT16SZ; port = ns_get16(rdata); rdata += NS_INT16SZ; len = SPRINTF((t, "%u %u %u ", priority, weight, port)); - T(addstr(t, len, &buf, &buflen)); + T(addstr(t, (size_t)len, &buf, &buflen)); /* Server. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); @@ -401,7 +410,7 @@ ns_sprintrrf(const u_char *msg, size_t m case ns_t_rp: /* Name1. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); - T(addstr(" ", 1, &buf, &buflen)); + T(addstr(" ", (size_t)1, &buf, &buflen)); /* Name2. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); @@ -415,13 +424,13 @@ ns_sprintrrf(const u_char *msg, size_t m goto formerr; /* Address. */ - (void) inet_ntop(AF_INET, rdata, buf, buflen); + (void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); rdata += NS_INADDRSZ; /* Protocol. */ len = SPRINTF((tmp, " %u ( ", *rdata)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); rdata += NS_INT8SZ; /* Bit map. */ @@ -432,19 +441,19 @@ ns_sprintrrf(const u_char *msg, size_t m do { if (c & 0200) { if (lcnt == 0) { - T(addstr("\n\t\t\t\t", 5, + T(addstr("\n\t\t\t\t", (size_t)5, &buf, &buflen)); lcnt = 10; spaced = 0; } len = SPRINTF((tmp, "%d ", n)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); lcnt--; } c <<= 1; } while (++n & 07); } - T(addstr(")", 1, &buf, &buflen)); + T(addstr(")", (size_t)1, &buf, &buflen)); break; } @@ -460,34 +469,38 @@ ns_sprintrrf(const u_char *msg, size_t m goto formerr; /* Key flags, Protocol, Algorithm. */ +#ifndef _LIBC key_id = dst_s_dns_key_id(rdata, edata-rdata); +#else + key_id = 0; +#endif keyflags = ns_get16(rdata); rdata += NS_INT16SZ; protocol = *rdata++; algorithm = *rdata++; len = SPRINTF((tmp, "0x%04x %u %u", keyflags, protocol, algorithm)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); /* Public key data. */ - len = b64_ntop(rdata, edata - rdata, + len = b64_ntop(rdata, (size_t)(edata - rdata), base64_key, sizeof base64_key); if (len < 0) goto formerr; if (len > 15) { - T(addstr(" (", 2, &buf, &buflen)); + T(addstr(" (", (size_t)2, &buf, &buflen)); leader = "\n\t\t"; spaced = 0; } else leader = " "; for (n = 0; n < len; n += 48) { T(addstr(leader, strlen(leader), &buf, &buflen)); - T(addstr(base64_key + n, MIN(len - n, 48), + T(addstr(base64_key + n, (size_t)MIN(len - n, 48), &buf, &buflen)); } if (len > 15) - T(addstr(" )", 2, &buf, &buflen)); + T(addstr(" )", (size_t)2, &buf, &buflen)); n = SPRINTF((tmp, " ; key_tag= %u", key_id)); - T(addstr(tmp, n, &buf, &buflen)); + T(addstr(tmp, (size_t)n, &buf, &buflen)); break; } @@ -495,7 +508,7 @@ ns_sprintrrf(const u_char *msg, size_t m case ns_t_sig: case ns_t_rrsig: { char base64_key[NS_MD5RSA_MAX_BASE64]; - u_int type, algorithm, labels, footprint; + u_int typ, algorithm, labels, footprint; const char *leader; u_long t; int n; @@ -504,39 +517,39 @@ ns_sprintrrf(const u_char *msg, size_t m goto formerr; /* Type covered, Algorithm, Label count, Original TTL. */ - type = ns_get16(rdata); rdata += NS_INT16SZ; + typ = ns_get16(rdata); rdata += NS_INT16SZ; algorithm = *rdata++; labels = *rdata++; t = ns_get32(rdata); rdata += NS_INT32SZ; len = SPRINTF((tmp, "%s %d %d %lu ", - p_type(type), algorithm, labels, t)); - T(addstr(tmp, len, &buf, &buflen)); + p_type((int)typ), algorithm, labels, t)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); if (labels > (u_int)dn_count_labels(name)) goto formerr; /* Signature expiry. */ t = ns_get32(rdata); rdata += NS_INT32SZ; len = SPRINTF((tmp, "%s ", p_secstodate(t))); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); /* Time signed. */ t = ns_get32(rdata); rdata += NS_INT32SZ; len = SPRINTF((tmp, "%s ", p_secstodate(t))); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); /* Signature Footprint. */ footprint = ns_get16(rdata); rdata += NS_INT16SZ; len = SPRINTF((tmp, "%u ", footprint)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); /* Signer's name. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); /* Signature. */ - len = b64_ntop(rdata, edata - rdata, + len = b64_ntop(rdata, (size_t)(edata - rdata), base64_key, sizeof base64_key); if (len > 15) { - T(addstr(" (", 2, &buf, &buflen)); + T(addstr(" (", (size_t)2, &buf, &buflen)); leader = "\n\t\t"; spaced = 0; } else @@ -545,16 +558,16 @@ ns_sprintrrf(const u_char *msg, size_t m goto formerr; for (n = 0; n < len; n += 48) { T(addstr(leader, strlen(leader), &buf, &buflen)); - T(addstr(base64_key + n, MIN(len - n, 48), + T(addstr(base64_key + n, (size_t)MIN(len - n, 48), &buf, &buflen)); } if (len > 15) - T(addstr(" )", 2, &buf, &buflen)); + T(addstr(" )", (size_t)2, &buf, &buflen)); break; } case ns_t_nxt: { - int n, c; + ptrdiff_t n, c; /* Next domain name. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); @@ -563,8 +576,8 @@ ns_sprintrrf(const u_char *msg, size_t m n = edata - rdata; for (c = 0; c < n*8; c++) if (NS_NXT_BIT_ISSET(c, rdata)) { - len = SPRINTF((tmp, " %s", p_type(c))); - T(addstr(tmp, len, &buf, &buflen)); + len = SPRINTF((tmp, " %s", p_type((int)c))); + T(addstr(tmp, (size_t)len, &buf, &buflen)); } break; } @@ -572,28 +585,29 @@ ns_sprintrrf(const u_char *msg, size_t m case ns_t_cert: { u_int c_type, key_tag, alg; int n; - unsigned int siz; - char base64_cert[8192], tmp[40]; + size_t siz; + char base64_cert[8192], tmp1[40]; const char *leader; c_type = ns_get16(rdata); rdata += NS_INT16SZ; key_tag = ns_get16(rdata); rdata += NS_INT16SZ; alg = (u_int) *rdata++; - len = SPRINTF((tmp, "%d %d %d ", c_type, key_tag, alg)); - T(addstr(tmp, len, &buf, &buflen)); + len = SPRINTF((tmp1, "%d %d %d ", c_type, key_tag, alg)); + T(addstr(tmp1, (size_t)len, &buf, &buflen)); siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ if (siz > sizeof(base64_cert) * 3/4) { const char *str = "record too long to print"; T(addstr(str, strlen(str), &buf, &buflen)); } else { - len = b64_ntop(rdata, edata-rdata, base64_cert, siz); + len = b64_ntop(rdata, (size_t)(edata-rdata), + base64_cert, siz); if (len < 0) goto formerr; else if (len > 15) { - T(addstr(" (", 2, &buf, &buflen)); + T(addstr(" (", (size_t)2, &buf, &buflen)); leader = "\n\t\t"; spaced = 0; } @@ -603,11 +617,11 @@ ns_sprintrrf(const u_char *msg, size_t m for (n = 0; n < len; n += 48) { T(addstr(leader, strlen(leader), &buf, &buflen)); - T(addstr(base64_cert + n, MIN(len - n, 48), + T(addstr(base64_cert + n, (size_t)MIN(len - n, 48), &buf, &buflen)); } if (len > 15) - T(addstr(" )", 2, &buf, &buflen)); + T(addstr(" )", (size_t)2, &buf, &buflen)); } break; } @@ -619,17 +633,17 @@ ns_sprintrrf(const u_char *msg, size_t m /* Algorithm name. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); - T(addstr(" ", 1, &buf, &buflen)); + T(addstr(" ", (size_t)1, &buf, &buflen)); /* Inception. */ t = ns_get32(rdata); rdata += NS_INT32SZ; len = SPRINTF((tmp, "%s ", p_secstodate(t))); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); /* Experation. */ t = ns_get32(rdata); rdata += NS_INT32SZ; len = SPRINTF((tmp, "%s ", p_secstodate(t))); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); /* Mode , Error, Key Size. */ /* Priority, Weight, Port. */ @@ -637,7 +651,7 @@ ns_sprintrrf(const u_char *msg, size_t m err = ns_get16(rdata); rdata += NS_INT16SZ; keysize = ns_get16(rdata); rdata += NS_INT16SZ; len = SPRINTF((tmp, "%u %u %u ", mode, err, keysize)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); /* XXX need to dump key, print otherdata length & other data */ break; @@ -648,7 +662,7 @@ ns_sprintrrf(const u_char *msg, size_t m int n; T(len = addname(msg, msglen, &rdata, origin, &buf, &buflen)); - T(addstr(" ", 1, &buf, &buflen)); + T(addstr(" ", (size_t)1, &buf, &buflen)); rdata += 8; /*%< time */ n = ns_get16(rdata); rdata += INT16SZ; rdata += n; /*%< sig */ @@ -666,7 +680,7 @@ ns_sprintrrf(const u_char *msg, size_t m /* prefix length */ if (rdlen == 0U) goto formerr; len = SPRINTF((tmp, "%d ", *rdata)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); pbit = *rdata; if (pbit > 128) goto formerr; pbyte = (pbit & ~7) / 8; @@ -677,7 +691,7 @@ ns_sprintrrf(const u_char *msg, size_t m if (rdata + pbyte >= edata) goto formerr; memset(&a, 0, sizeof(a)); memcpy(&a.s6_addr[pbyte], rdata, sizeof(a) - pbyte); - (void) inet_ntop(AF_INET6, &a, buf, buflen); + (void) inet_ntop(AF_INET6, &a, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); rdata += sizeof(a) - pbyte; } @@ -686,7 +700,7 @@ ns_sprintrrf(const u_char *msg, size_t m if (pbit == 0) break; if (rdata >= edata) goto formerr; - T(addstr(" ", 1, &buf, &buflen)); + T(addstr(" ", (size_t)1, &buf, &buflen)); T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); break; @@ -694,7 +708,7 @@ ns_sprintrrf(const u_char *msg, size_t m case ns_t_opt: { len = SPRINTF((tmp, "%u bytes", class)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); break; } @@ -708,21 +722,21 @@ ns_sprintrrf(const u_char *msg, size_t m t = ns_get16(rdata); rdata += NS_INT16SZ; len = SPRINTF((tmp, "%u ", t)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); } else if (rdlen < 2U) goto formerr; len = SPRINTF((tmp, "%u ", *rdata)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); rdata++; len = SPRINTF((tmp, "%u ", *rdata)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); rdata++; while (rdata < edata) { len = SPRINTF((tmp, "%02X", *rdata)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); rdata++; } break; @@ -733,17 +747,17 @@ ns_sprintrrf(const u_char *msg, size_t m u_int t, w, l, j, k, c; len = SPRINTF((tmp, "%u ", *rdata)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); rdata++; len = SPRINTF((tmp, "%u ", *rdata)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); rdata++; t = ns_get16(rdata); rdata += NS_INT16SZ; len = SPRINTF((tmp, "%u ", t)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); t = *rdata++; if (t == 0) { @@ -751,7 +765,7 @@ ns_sprintrrf(const u_char *msg, size_t m } else { while (t-- > 0) { len = SPRINTF((tmp, "%02X", *rdata)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); rdata++; } } @@ -763,54 +777,54 @@ ns_sprintrrf(const u_char *msg, size_t m while (t > 0) { switch (t) { case 1: - tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; - tmp[1] = base32hex[((rdata[0]<<2)&0x1c)]; + tmp[0] = base32hex[(((uint32_t)rdata[0]>>3)&0x1f)]; + tmp[1] = base32hex[(((uint32_t)rdata[0]<<2)&0x1c)]; tmp[2] = tmp[3] = tmp[4] = '='; tmp[5] = tmp[6] = tmp[7] = '='; break; case 2: - tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; - tmp[1] = base32hex[((rdata[0]<<2)&0x1c)| - ((rdata[1]>>6)&0x03)]; - tmp[2] = base32hex[((rdata[1]>>1)&0x1f)]; - tmp[3] = base32hex[((rdata[1]<<4)&0x10)]; + tmp[0] = base32hex[(((uint32_t)rdata[0]>>3)&0x1f)]; + tmp[1] = base32hex[(((uint32_t)rdata[0]<<2)&0x1c)| + (((uint32_t)rdata[1]>>6)&0x03)]; + tmp[2] = base32hex[(((uint32_t)rdata[1]>>1)&0x1f)]; + tmp[3] = base32hex[(((uint32_t)rdata[1]<<4)&0x10)]; tmp[4] = tmp[5] = tmp[6] = tmp[7] = '='; break; case 3: - tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; - tmp[1] = base32hex[((rdata[0]<<2)&0x1c)| - ((rdata[1]>>6)&0x03)]; - tmp[2] = base32hex[((rdata[1]>>1)&0x1f)]; - tmp[3] = base32hex[((rdata[1]<<4)&0x10)| - ((rdata[2]>>4)&0x0f)]; - tmp[4] = base32hex[((rdata[2]<<1)&0x1e)]; + tmp[0] = base32hex[(((uint32_t)rdata[0]>>3)&0x1f)]; + tmp[1] = base32hex[(((uint32_t)rdata[0]<<2)&0x1c)| + (((uint32_t)rdata[1]>>6)&0x03)]; + tmp[2] = base32hex[(((uint32_t)rdata[1]>>1)&0x1f)]; + tmp[3] = base32hex[(((uint32_t)rdata[1]<<4)&0x10)| + (((uint32_t)rdata[2]>>4)&0x0f)]; + tmp[4] = base32hex[(((uint32_t)rdata[2]<<1)&0x1e)]; tmp[5] = tmp[6] = tmp[7] = '='; break; case 4: - tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; - tmp[1] = base32hex[((rdata[0]<<2)&0x1c)| - ((rdata[1]>>6)&0x03)]; - tmp[2] = base32hex[((rdata[1]>>1)&0x1f)]; - tmp[3] = base32hex[((rdata[1]<<4)&0x10)| - ((rdata[2]>>4)&0x0f)]; - tmp[4] = base32hex[((rdata[2]<<1)&0x1e)| - ((rdata[3]>>7)&0x01)]; - tmp[5] = base32hex[((rdata[3]>>2)&0x1f)]; - tmp[6] = base32hex[(rdata[3]<<3)&0x18]; + tmp[0] = base32hex[(((uint32_t)rdata[0]>>3)&0x1f)]; + tmp[1] = base32hex[(((uint32_t)rdata[0]<<2)&0x1c)| + (((uint32_t)rdata[1]>>6)&0x03)]; + tmp[2] = base32hex[(((uint32_t)rdata[1]>>1)&0x1f)]; + tmp[3] = base32hex[(((uint32_t)rdata[1]<<4)&0x10)| + (((uint32_t)rdata[2]>>4)&0x0f)]; + tmp[4] = base32hex[(((uint32_t)rdata[2]<<1)&0x1e)| + (((uint32_t)rdata[3]>>7)&0x01)]; + tmp[5] = base32hex[(((uint32_t)rdata[3]>>2)&0x1f)]; + tmp[6] = base32hex[((uint32_t)rdata[3]<<3)&0x18]; tmp[7] = '='; break; default: - tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; - tmp[1] = base32hex[((rdata[0]<<2)&0x1c)| - ((rdata[1]>>6)&0x03)]; - tmp[2] = base32hex[((rdata[1]>>1)&0x1f)]; - tmp[3] = base32hex[((rdata[1]<<4)&0x10)| - ((rdata[2]>>4)&0x0f)]; - tmp[4] = base32hex[((rdata[2]<<1)&0x1e)| - ((rdata[3]>>7)&0x01)]; - tmp[5] = base32hex[((rdata[3]>>2)&0x1f)]; - tmp[6] = base32hex[((rdata[3]<<3)&0x18)| - ((rdata[4]>>5)&0x07)]; + tmp[0] = base32hex[(((uint32_t)rdata[0]>>3)&0x1f)]; + tmp[1] = base32hex[(((uint32_t)rdata[0]<<2)&0x1c)| + (((uint32_t)rdata[1]>>6)&0x03)]; + tmp[2] = base32hex[(((uint32_t)rdata[1]>>1)&0x1f)]; + tmp[3] = base32hex[(((uint32_t)rdata[1]<<4)&0x10)| + (((uint32_t)rdata[2]>>4)&0x0f)]; + tmp[4] = base32hex[(((uint32_t)rdata[2]<<1)&0x1e)| + (((uint32_t)rdata[3]>>7)&0x01)]; + tmp[5] = base32hex[(((uint32_t)rdata[3]>>2)&0x1f)]; + tmp[6] = base32hex[(((uint32_t)rdata[3]<<3)&0x18)| + (((uint32_t)rdata[4]>>5)&0x07)]; tmp[7] = base32hex[(rdata[4]&0x1f)]; break; } @@ -834,8 +848,8 @@ ns_sprintrrf(const u_char *msg, size_t m if ((rdata[j] & (0x80 >> k)) == 0) continue; c = w * 256 + j * 8 + k; - len = SPRINTF((tmp, " %s", p_type(c))); - T(addstr(tmp, len, &buf, &buflen)); + len = SPRINTF((tmp, " %s", p_type((ns_type)c))); + T(addstr(tmp, (size_t)len, &buf, &buflen)); } } rdata += l; @@ -858,8 +872,8 @@ ns_sprintrrf(const u_char *msg, size_t m if ((rdata[j] & (0x80 >> k)) == 0) continue; c = w * 256 + j * 8 + k; - len = SPRINTF((tmp, " %s", p_type(c))); - T(addstr(tmp, len, &buf, &buflen)); + len = SPRINTF((tmp, " %s", p_type((ns_type)c))); + T(addstr(tmp, (size_t)len, &buf, &buflen)); } } rdata += l; @@ -873,12 +887,13 @@ ns_sprintrrf(const u_char *msg, size_t m char base64_dhcid[8192]; const char *leader; - siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ + siz = (int)(edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ if (siz > sizeof(base64_dhcid) * 3/4) { const char *str = "record too long to print"; T(addstr(str, strlen(str), &buf, &buflen)); } else { - len = b64_ntop(rdata, edata-rdata, base64_dhcid, siz); + len = b64_ntop(rdata, (size_t)(edata-rdata), + base64_dhcid, siz); if (len < 0) goto formerr; @@ -894,12 +909,13 @@ ns_sprintrrf(const u_char *msg, size_t m for (n = 0; n < len; n += 48) { T(addstr(leader, strlen(leader), &buf, &buflen)); - T(addstr(base64_dhcid + n, MIN(len - n, 48), - &buf, &buflen)); + T(addstr(base64_dhcid + n, + (size_t)MIN(len - n, 48), &buf, &buflen)); } if (len > 15) T(addstr(" )", 2, &buf, &buflen)); } + break; } case ns_t_ipseckey: { @@ -931,15 +947,15 @@ ns_sprintrrf(const u_char *msg, size_t m } len = SPRINTF((tmp, "%u ", *rdata)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); rdata++; len = SPRINTF((tmp, "%u ", *rdata)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); rdata++; len = SPRINTF((tmp, "%u ", *rdata)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); rdata++; switch (rdata[-2]) { @@ -947,12 +963,12 @@ ns_sprintrrf(const u_char *msg, size_t m T(addstr(".", 1, &buf, &buflen)); break; case 1: - (void) inet_ntop(AF_INET, rdata, buf, buflen); + (void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); rdata += 4; break; case 2: - (void) inet_ntop(AF_INET6, rdata, buf, buflen); + (void) inet_ntop(AF_INET6, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); rdata += 16; break; @@ -964,12 +980,13 @@ ns_sprintrrf(const u_char *msg, size_t m if (rdata >= edata) break; - siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ + siz = (int)(edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ if (siz > sizeof(base64_key) * 3/4) { const char *str = "record too long to print"; T(addstr(str, strlen(str), &buf, &buflen)); } else { - len = b64_ntop(rdata, edata-rdata, base64_key, siz); + len = b64_ntop(rdata, (size_t)(edata-rdata), + base64_key, siz); if (len < 0) goto formerr; @@ -985,12 +1002,13 @@ ns_sprintrrf(const u_char *msg, size_t m for (n = 0; n < len; n += 48) { T(addstr(leader, strlen(leader), &buf, &buflen)); - T(addstr(base64_key + n, MIN(len - n, 48), - &buf, &buflen)); + T(addstr(base64_key + n, + (size_t)MIN(len - n, 48), &buf, &buflen)); } if (len > 15) T(addstr(" )", 2, &buf, &buflen)); } + break; } case ns_t_hip: { @@ -1010,11 +1028,11 @@ ns_sprintrrf(const u_char *msg, size_t m T(addstr(str, strlen(str), &buf, &buflen)); } else { len = sprintf(tmp, "( %u ", algorithm); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); for (i = 0; i < hip_len; i++) { len = sprintf(tmp, "%02X", *rdata); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); rdata++; } T(addstr(leader, strlen(leader), &buf, &buflen)); @@ -1023,7 +1041,7 @@ ns_sprintrrf(const u_char *msg, size_t m if (len < 0) goto formerr; - T(addstr(base64_key, len, &buf, &buflen)); + T(addstr(base64_key, (size_t)len, &buf, &buflen)); rdata += key_len; while (rdata < edata) { @@ -1040,7 +1058,8 @@ ns_sprintrrf(const u_char *msg, size_t m comment = "unknown RR type"; goto hexify; } - return (buf - obuf); + _DIAGASSERT(__type_fit(int, buf - obuf)); + return (int)(buf - obuf); formerr: comment = "RR format error"; hexify: { @@ -1049,18 +1068,18 @@ ns_sprintrrf(const u_char *msg, size_t m len = SPRINTF((tmp, "\\# %u%s\t; %s", (unsigned)(edata - rdata), rdlen != 0U ? " (" : "", comment)); - T(addstr(tmp, len, &buf, &buflen)); + T(addstr(tmp, (size_t)len, &buf, &buflen)); while (rdata < edata) { p = tmp; p += SPRINTF((p, "\n\t")); spaced = 0; - n = MIN(16, edata - rdata); + n = MIN(16, (int)(edata - rdata)); for (m = 0; m < n; m++) p += SPRINTF((p, "%02x ", rdata[m])); - T(addstr(tmp, p - tmp, &buf, &buflen)); + T(addstr(tmp, (size_t)(p - tmp), &buf, &buflen)); if (n < 16) { - T(addstr(")", 1, &buf, &buflen)); - T(addtab(p - tmp + 1, 48, spaced, &buf, &buflen)); + T(addstr(")", (size_t)1, &buf, &buflen)); + T(addtab((size_t)(p - tmp + 1), (size_t)48, spaced, &buf, &buflen)); } p = tmp; p += SPRINTF((p, "; ")); @@ -1068,10 +1087,11 @@ ns_sprintrrf(const u_char *msg, size_t m *p++ = (isascii(rdata[m]) && isprint(rdata[m])) ? rdata[m] : '.'; - T(addstr(tmp, p - tmp, &buf, &buflen)); + T(addstr(tmp, (size_t)(p - tmp), &buf, &buflen)); rdata += n; } - return (buf - obuf); + _DIAGASSERT(__type_fit(int, buf - obuf)); + return (int)(buf - obuf); } } @@ -1127,7 +1147,7 @@ charstr(const u_char *rdata, const u_cha size_t save_buflen = *buflen; char *save_buf = *buf; - if (addstr("\"", 1, buf, buflen) < 0) + if (addstr("\"", (size_t)1, buf, buflen) < 0) goto enospc; if (rdata < edata) { int n = *rdata; @@ -1136,18 +1156,19 @@ charstr(const u_char *rdata, const u_cha rdata++; while (n-- > 0) { if (strchr("\n\"\\", *rdata) != NULL) - if (addstr("\\", 1, buf, buflen) < 0) + if (addstr("\\", (size_t)1, buf, buflen) < 0) goto enospc; - if (addstr((const char *)rdata, 1, + if (addstr((const char *)rdata, (size_t)1, buf, buflen) < 0) goto enospc; rdata++; } } } - if (addstr("\"", 1, buf, buflen) < 0) + if (addstr("\"", (size_t)1, buf, buflen) < 0) goto enospc; - return (rdata - odata); + _DIAGASSERT(__type_fit(int, rdata - odata)); + return (int)(rdata - odata); enospc: errno = ENOSPC; *buf = save_buf; @@ -1164,7 +1185,7 @@ addname(const u_char *msg, size_t msglen char *save_buf = *buf; int n; - n = dn_expand(msg, msg + msglen, *pp, *buf, *buflen); + n = dn_expand(msg, msg + msglen, *pp, *buf, (int)*buflen); if (n < 0) goto enospc; /*%< Guess. */ newlen = prune_origin(*buf, origin); @@ -1191,7 +1212,8 @@ addname(const u_char *msg, size_t msglen *pp += n; addlen(newlen, buf, buflen); **buf = '\0'; - return (newlen); + _DIAGASSERT(__type_fit(int, newlen)); + return (int)newlen; enospc: errno = ENOSPC; *buf = save_buf; @@ -1222,14 +1244,14 @@ static int addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) { size_t save_buflen = *buflen; char *save_buf = *buf; - int t; + ptrdiff_t t; if (spaced || len >= target - 1) { - T(addstr(" ", 2, buf, buflen)); + T(addstr(" ", (size_t)2, buf, buflen)); spaced = 1; } else { for (t = (target - len - 1) / 8; t >= 0; t--) - if (addstr("\t", 1, buf, buflen) < 0) { + if (addstr("\t", (size_t)1, buf, buflen) < 0) { *buflen = save_buflen; *buf = save_buf; return (-1); diff -pruN /home/reed/src/isc/libbind/libbind/nameser/ns_rdata.c /usr/src/lib/libc/nameser/ns_rdata.c --- /home/reed/src/isc/libbind/libbind/nameser/ns_rdata.c 2009-01-23 17:49:15.000000000 -0600 +++ /usr/src/lib/libc/nameser/ns_rdata.c 1969-12-31 18:00:00.000000000 -0600 @@ -1,294 +0,0 @@ -/* - * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef lint -static const char rcsid[] = "$Id: ns_rdata.c,v 1.2 2009/01/23 23:49:15 tbox Exp $"; -#endif - -#include "port_before.h" - -#if __OpenBSD__ -#include -#endif -#include -#include - -#include -#include -#include - -#include "port_after.h" - -#define CONSUME_SRC \ - do { \ - rdata += n, rdlen -= n; \ - } while (0) - -#define CONSUME_DST \ - do { \ - nrdata += n, nrdsiz -= n, nrdlen += n; \ - } while (0) - -#define UNPACK_DNAME \ - do { \ - size_t t; \ - \ - if ((n = ns_name_unpack2(msg,eom,rdata,nrdata,nrdsiz,&t))<0) {\ - errno = EMSGSIZE; \ - return (-1); \ - } \ - CONSUME_SRC; \ - n = t; \ - CONSUME_DST; \ - } while (0) - -#define UNPACK_SOME(x) \ - do { \ - n = (x); \ - if ((size_t)n > rdlen || (size_t)n > nrdsiz) { \ - errno = EMSGSIZE; \ - return (-1); \ - } \ - memcpy(nrdata, rdata, n); \ - CONSUME_SRC; CONSUME_DST; \ - } while (0) - -#define UNPACK_REST(x) \ - do { \ - n = (x); \ - if ((size_t)n != rdlen) { \ - errno = EMSGSIZE; \ - return (-1); \ - } \ - memcpy(nrdata, rdata, n); \ - CONSUME_SRC; CONSUME_DST; \ - } while (0) - -ssize_t -ns_rdata_unpack(const u_char *msg, const u_char *eom, - ns_type type, const u_char *rdata, size_t rdlen, - u_char *nrdata, size_t nrdsiz) -{ - size_t nrdlen = 0; - int n; - - switch (type) { - case ns_t_a: - UNPACK_REST(NS_INADDRSZ); - break; - case ns_t_aaaa: - UNPACK_REST(NS_IN6ADDRSZ); - break; - case ns_t_cname: - case ns_t_mb: - case ns_t_mg: - case ns_t_mr: - case ns_t_ns: - case ns_t_ptr: - case ns_t_dname: - UNPACK_DNAME; - break; - case ns_t_soa: - UNPACK_DNAME; - UNPACK_DNAME; - UNPACK_SOME(NS_INT32SZ * 5); - break; - case ns_t_mx: - case ns_t_afsdb: - case ns_t_rt: - UNPACK_SOME(NS_INT16SZ); - UNPACK_DNAME; - break; - case ns_t_px: - UNPACK_SOME(NS_INT16SZ); - UNPACK_DNAME; - UNPACK_DNAME; - break; - case ns_t_srv: - UNPACK_SOME(NS_INT16SZ * 3); - UNPACK_DNAME; - break; - case ns_t_minfo: - case ns_t_rp: - UNPACK_DNAME; - UNPACK_DNAME; - break; - default: - UNPACK_SOME(rdlen); - break; - } - if (rdlen > 0) { - errno = EMSGSIZE; - return (-1); - } - return (nrdlen); -} - -#define EQUAL_CONSUME \ - do { \ - rdata1 += n, rdlen1 -= n; \ - rdata2 += n, rdlen2 -= n; \ - } while (0) - -#define EQUAL_DNAME \ - do { \ - ssize_t n; \ - \ - if (rdlen1 != rdlen2) \ - return (0); \ - n = ns_name_eq(rdata1, rdlen1, rdata2, rdlen2); \ - if (n <= 0) \ - return (n); \ - n = rdlen1; \ - EQUAL_CONSUME; \ - } while (0) - -#define EQUAL_SOME(x) \ - do { \ - size_t n = (x); \ - \ - if (n > rdlen1 || n > rdlen2) { \ - errno = EMSGSIZE; \ - return (-1); \ - } \ - if (memcmp(rdata1, rdata2, n) != 0) \ - return (0); \ - EQUAL_CONSUME; \ - } while (0) - -int -ns_rdata_equal(ns_type type, - const u_char *rdata1, size_t rdlen1, - const u_char *rdata2, size_t rdlen2) -{ - switch (type) { - case ns_t_cname: - case ns_t_mb: - case ns_t_mg: - case ns_t_mr: - case ns_t_ns: - case ns_t_ptr: - case ns_t_dname: - EQUAL_DNAME; - break; - case ns_t_soa: - /* "There can be only one." --Highlander */ - break; - case ns_t_mx: - case ns_t_afsdb: - case ns_t_rt: - EQUAL_SOME(NS_INT16SZ); - EQUAL_DNAME; - break; - case ns_t_px: - EQUAL_SOME(NS_INT16SZ); - EQUAL_DNAME; - EQUAL_DNAME; - break; - case ns_t_srv: - EQUAL_SOME(NS_INT16SZ * 3); - EQUAL_DNAME; - break; - case ns_t_minfo: - case ns_t_rp: - EQUAL_DNAME; - EQUAL_DNAME; - break; - default: - EQUAL_SOME(rdlen1); - break; - } - if (rdlen1 != 0 || rdlen2 != 0) - return (0); - return (1); -} - -#define REFERS_DNAME \ - do { \ - int n; \ - \ - n = ns_name_eq(rdata, rdlen, nname, NS_MAXNNAME); \ - if (n < 0) \ - return (-1); \ - if (n > 0) \ - return (1); \ - n = dn_skipname(rdata, rdata + rdlen); \ - if (n < 0) \ - return (-1); \ - CONSUME_SRC; \ - } while (0) - -#define REFERS_SOME(x) \ - do { \ - size_t n = (x); \ - \ - if (n > rdlen) { \ - errno = EMSGSIZE; \ - return (-1); \ - } \ - CONSUME_SRC; \ - } while (0) - -int -ns_rdata_refers(ns_type type, - const u_char *rdata, size_t rdlen, - const u_char *nname) -{ - switch (type) { - case ns_t_cname: - case ns_t_mb: - case ns_t_mg: - case ns_t_mr: - case ns_t_ns: - case ns_t_ptr: - case ns_t_dname: - REFERS_DNAME; - break; - case ns_t_soa: - REFERS_DNAME; - REFERS_DNAME; - REFERS_SOME(NS_INT32SZ * 5); - break; - case ns_t_mx: - case ns_t_afsdb: - case ns_t_rt: - REFERS_SOME(NS_INT16SZ); - REFERS_DNAME; - break; - case ns_t_px: - REFERS_SOME(NS_INT16SZ); - REFERS_DNAME; - REFERS_DNAME; - break; - case ns_t_srv: - REFERS_SOME(NS_INT16SZ * 3); - REFERS_DNAME; - break; - case ns_t_minfo: - case ns_t_rp: - REFERS_DNAME; - REFERS_DNAME; - break; - default: - REFERS_SOME(rdlen); - break; - } - if (rdlen != 0) { - errno = EMSGSIZE; - return (-1); - } - return (0); -} diff -pruN /home/reed/src/isc/libbind/libbind/nameser/ns_samedomain.c /usr/src/lib/libc/nameser/ns_samedomain.c --- /home/reed/src/isc/libbind/libbind/nameser/ns_samedomain.c 2005-04-26 23:56:40.000000000 -0500 +++ /usr/src/lib/libc/nameser/ns_samedomain.c 2013-06-05 09:26:12.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: ns_samedomain.c,v 1.8 2012/11/22 20:22:31 christos Exp $ */ + /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995,1999 by Internet Software Consortium. @@ -15,8 +17,13 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #ifndef lint -static const char rcsid[] = "$Id: ns_samedomain.c,v 1.6 2005/04/27 04:56:40 sra Exp $"; +#ifdef notdef +static const char rcsid[] = "Id: ns_samedomain.c,v 1.6 2005/04/27 04:56:40 sra Exp"; +#else +__RCSID("$NetBSD: ns_samedomain.c,v 1.8 2012/11/22 20:22:31 christos Exp $"); +#endif #endif #include "port_before.h" @@ -28,6 +35,7 @@ static const char rcsid[] = "$Id: ns_sam #include "port_after.h" +#ifdef _LIBRESOLV /*% * Check whether a name belongs to a domain. * @@ -49,8 +57,8 @@ static const char rcsid[] = "$Id: ns_sam int ns_samedomain(const char *a, const char *b) { - size_t la, lb; - int diff, i, escaped; + size_t la, lb, i; + int diff, escaped; const char *cp; la = strlen(a); @@ -60,8 +68,8 @@ ns_samedomain(const char *a, const char if (la != 0U && a[la - 1] == '.') { escaped = 0; /* Note this loop doesn't get executed if la==1. */ - for (i = la - 2; i >= 0; i--) - if (a[i] == '\\') { + for (i = la - 1; i > 0; i--) + if (a[i - 1] == '\\') { if (escaped) escaped = 0; else @@ -76,8 +84,8 @@ ns_samedomain(const char *a, const char if (lb != 0U && b[lb - 1] == '.') { escaped = 0; /* note this loop doesn't get executed if lb==1 */ - for (i = lb - 2; i >= 0; i--) - if (b[i] == '\\') { + for (i = lb - 1; i > 0; i--) + if (b[i - 1] == '\\') { if (escaped) escaped = 0; else @@ -102,7 +110,7 @@ ns_samedomain(const char *a, const char /* Ok, we know la > lb. */ - diff = la - lb; + diff = (int)(la - lb); /* * If 'a' is only 1 character longer than 'b', then it can't be @@ -125,8 +133,8 @@ ns_samedomain(const char *a, const char * and thus not a really a label separator. */ escaped = 0; - for (i = diff - 2; i >= 0; i--) - if (a[i] == '\\') { + for (i = diff - 1; i > 0; i--) + if (a[i - 1] == '\\') { if (escaped) escaped = 0; else @@ -148,7 +156,8 @@ int ns_subdomain(const char *a, const char *b) { return (ns_samename(a, b) != 1 && ns_samedomain(a, b)); } - +#endif +#ifdef _LIBC /*% * make a canonical copy of domain name "src" * @@ -203,5 +212,5 @@ ns_samename(const char *a, const char *b else return (0); } - +#endif /*! \file */ diff -pruN /home/reed/src/isc/libbind/libbind/nameser/ns_sign.c /usr/src/lib/libc/nameser/ns_sign.c --- /home/reed/src/isc/libbind/libbind/nameser/ns_sign.c 2006-03-09 17:57:56.000000000 -0600 +++ /usr/src/lib/libc/nameser/ns_sign.c 1969-12-31 18:00:00.000000000 -0600 @@ -1,387 +0,0 @@ -/* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1999 by Internet Software Consortium, Inc. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef lint -static const char rcsid[] = "$Id: ns_sign.c,v 1.6 2006/03/09 23:57:56 marka Exp $"; -#endif - -/* Import. */ - -#include "port_before.h" -#include "fd_setsize.h" - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "port_after.h" - -#define BOUNDS_CHECK(ptr, count) \ - do { \ - if ((ptr) + (count) > eob) { \ - errno = EMSGSIZE; \ - return(NS_TSIG_ERROR_NO_SPACE); \ - } \ - } while (0) - -/*% - * ns_sign - * - * Parameters: - *\li msg message to be sent - *\li msglen input - length of message - * output - length of signed message - *\li msgsize length of buffer containing message - *\li error value to put in the error field - *\li key tsig key used for signing - *\li querysig (response), the signature in the query - *\li querysiglen (response), the length of the signature in the query - *\li sig a buffer to hold the generated signature - *\li siglen input - length of signature buffer - * output - length of signature - * - * Errors: - *\li - bad input data (-1) - *\li - bad key / sign failed (-BADKEY) - *\li - not enough space (NS_TSIG_ERROR_NO_SPACE) - */ -int -ns_sign(u_char *msg, int *msglen, int msgsize, int error, void *k, - const u_char *querysig, int querysiglen, u_char *sig, int *siglen, - time_t in_timesigned) -{ - return(ns_sign2(msg, msglen, msgsize, error, k, - querysig, querysiglen, sig, siglen, - in_timesigned, NULL, NULL)); -} - -int -ns_sign2(u_char *msg, int *msglen, int msgsize, int error, void *k, - const u_char *querysig, int querysiglen, u_char *sig, int *siglen, - time_t in_timesigned, u_char **dnptrs, u_char **lastdnptr) -{ - HEADER *hp = (HEADER *)msg; - DST_KEY *key = (DST_KEY *)k; - u_char *cp, *eob; - u_char *lenp; - u_char *alg; - int n; - time_t timesigned; - u_char name[NS_MAXCDNAME]; - - dst_init(); - if (msg == NULL || msglen == NULL || sig == NULL || siglen == NULL) - return (-1); - - cp = msg + *msglen; - eob = msg + msgsize; - - /* Name. */ - if (key != NULL && error != ns_r_badsig && error != ns_r_badkey) { - n = ns_name_pton(key->dk_key_name, name, sizeof name); - if (n != -1) - n = ns_name_pack(name, cp, eob - cp, - (const u_char **)dnptrs, - (const u_char **)lastdnptr); - - } else { - n = ns_name_pton("", name, sizeof name); - if (n != -1) - n = ns_name_pack(name, cp, eob - cp, NULL, NULL); - } - if (n < 0) - return (NS_TSIG_ERROR_NO_SPACE); - cp += n; - - /* Type, class, ttl, length (not filled in yet). */ - BOUNDS_CHECK(cp, INT16SZ + INT16SZ + INT32SZ + INT16SZ); - PUTSHORT(ns_t_tsig, cp); - PUTSHORT(ns_c_any, cp); - PUTLONG(0, cp); /*%< TTL */ - lenp = cp; - cp += 2; - - /* Alg. */ - if (key != NULL && error != ns_r_badsig && error != ns_r_badkey) { - if (key->dk_alg != KEY_HMAC_MD5) - return (-ns_r_badkey); - n = dn_comp(NS_TSIG_ALG_HMAC_MD5, cp, eob - cp, NULL, NULL); - } - else - n = dn_comp("", cp, eob - cp, NULL, NULL); - if (n < 0) - return (NS_TSIG_ERROR_NO_SPACE); - alg = cp; - cp += n; - - /* Time. */ - BOUNDS_CHECK(cp, INT16SZ + INT32SZ + INT16SZ); - PUTSHORT(0, cp); - timesigned = time(NULL); - if (error != ns_r_badtime) - PUTLONG(timesigned, cp); - else - PUTLONG(in_timesigned, cp); - PUTSHORT(NS_TSIG_FUDGE, cp); - - /* Compute the signature. */ - if (key != NULL && error != ns_r_badsig && error != ns_r_badkey) { - void *ctx; - u_char buf[NS_MAXCDNAME], *cp2; - int n; - - dst_sign_data(SIG_MODE_INIT, key, &ctx, NULL, 0, NULL, 0); - - /* Digest the query signature, if this is a response. */ - if (querysiglen > 0 && querysig != NULL) { - u_int16_t len_n = htons(querysiglen); - dst_sign_data(SIG_MODE_UPDATE, key, &ctx, - (u_char *)&len_n, INT16SZ, NULL, 0); - dst_sign_data(SIG_MODE_UPDATE, key, &ctx, - querysig, querysiglen, NULL, 0); - } - - /* Digest the message. */ - dst_sign_data(SIG_MODE_UPDATE, key, &ctx, msg, *msglen, - NULL, 0); - - /* Digest the key name. */ - n = ns_name_ntol(name, buf, sizeof(buf)); - INSIST(n > 0); - dst_sign_data(SIG_MODE_UPDATE, key, &ctx, buf, n, NULL, 0); - - /* Digest the class and TTL. */ - cp2 = buf; - PUTSHORT(ns_c_any, cp2); - PUTLONG(0, cp2); - dst_sign_data(SIG_MODE_UPDATE, key, &ctx, buf, cp2-buf, - NULL, 0); - - /* Digest the algorithm. */ - n = ns_name_ntol(alg, buf, sizeof(buf)); - INSIST(n > 0); - dst_sign_data(SIG_MODE_UPDATE, key, &ctx, buf, n, NULL, 0); - - /* Digest the time signed, fudge, error, and other data */ - cp2 = buf; - PUTSHORT(0, cp2); /*%< Top 16 bits of time */ - if (error != ns_r_badtime) - PUTLONG(timesigned, cp2); - else - PUTLONG(in_timesigned, cp2); - PUTSHORT(NS_TSIG_FUDGE, cp2); - PUTSHORT(error, cp2); /*%< Error */ - if (error != ns_r_badtime) - PUTSHORT(0, cp2); /*%< Other data length */ - else { - PUTSHORT(INT16SZ+INT32SZ, cp2); /*%< Other data length */ - PUTSHORT(0, cp2); /*%< Top 16 bits of time */ - PUTLONG(timesigned, cp2); - } - dst_sign_data(SIG_MODE_UPDATE, key, &ctx, buf, cp2-buf, - NULL, 0); - - n = dst_sign_data(SIG_MODE_FINAL, key, &ctx, NULL, 0, - sig, *siglen); - if (n < 0) - return (-ns_r_badkey); - *siglen = n; - } else - *siglen = 0; - - /* Add the signature. */ - BOUNDS_CHECK(cp, INT16SZ + (*siglen)); - PUTSHORT(*siglen, cp); - memcpy(cp, sig, *siglen); - cp += (*siglen); - - /* The original message ID & error. */ - BOUNDS_CHECK(cp, INT16SZ + INT16SZ); - PUTSHORT(ntohs(hp->id), cp); /*%< already in network order */ - PUTSHORT(error, cp); - - /* Other data. */ - BOUNDS_CHECK(cp, INT16SZ); - if (error != ns_r_badtime) - PUTSHORT(0, cp); /*%< Other data length */ - else { - PUTSHORT(INT16SZ+INT32SZ, cp); /*%< Other data length */ - BOUNDS_CHECK(cp, INT32SZ+INT16SZ); - PUTSHORT(0, cp); /*%< Top 16 bits of time */ - PUTLONG(timesigned, cp); - } - - /* Go back and fill in the length. */ - PUTSHORT(cp - lenp - INT16SZ, lenp); - - hp->arcount = htons(ntohs(hp->arcount) + 1); - *msglen = (cp - msg); - return (0); -} - -int -ns_sign_tcp_init(void *k, const u_char *querysig, int querysiglen, - ns_tcp_tsig_state *state) -{ - dst_init(); - if (state == NULL || k == NULL || querysig == NULL || querysiglen < 0) - return (-1); - state->counter = -1; - state->key = k; - if (state->key->dk_alg != KEY_HMAC_MD5) - return (-ns_r_badkey); - if (querysiglen > (int)sizeof(state->sig)) - return (-1); - memcpy(state->sig, querysig, querysiglen); - state->siglen = querysiglen; - return (0); -} - -int -ns_sign_tcp(u_char *msg, int *msglen, int msgsize, int error, - ns_tcp_tsig_state *state, int done) -{ - return (ns_sign_tcp2(msg, msglen, msgsize, error, state, - done, NULL, NULL)); -} - -int -ns_sign_tcp2(u_char *msg, int *msglen, int msgsize, int error, - ns_tcp_tsig_state *state, int done, - u_char **dnptrs, u_char **lastdnptr) -{ - u_char *cp, *eob, *lenp; - u_char buf[MAXDNAME], *cp2; - HEADER *hp = (HEADER *)msg; - time_t timesigned; - int n; - - if (msg == NULL || msglen == NULL || state == NULL) - return (-1); - - state->counter++; - if (state->counter == 0) - return (ns_sign2(msg, msglen, msgsize, error, state->key, - state->sig, state->siglen, - state->sig, &state->siglen, 0, - dnptrs, lastdnptr)); - - if (state->siglen > 0) { - u_int16_t siglen_n = htons(state->siglen); - dst_sign_data(SIG_MODE_INIT, state->key, &state->ctx, - NULL, 0, NULL, 0); - dst_sign_data(SIG_MODE_UPDATE, state->key, &state->ctx, - (u_char *)&siglen_n, INT16SZ, NULL, 0); - dst_sign_data(SIG_MODE_UPDATE, state->key, &state->ctx, - state->sig, state->siglen, NULL, 0); - state->siglen = 0; - } - - dst_sign_data(SIG_MODE_UPDATE, state->key, &state->ctx, msg, *msglen, - NULL, 0); - - if (done == 0 && (state->counter % 100 != 0)) - return (0); - - cp = msg + *msglen; - eob = msg + msgsize; - - /* Name. */ - n = dn_comp(state->key->dk_key_name, cp, eob - cp, dnptrs, lastdnptr); - if (n < 0) - return (NS_TSIG_ERROR_NO_SPACE); - cp += n; - - /* Type, class, ttl, length (not filled in yet). */ - BOUNDS_CHECK(cp, INT16SZ + INT16SZ + INT32SZ + INT16SZ); - PUTSHORT(ns_t_tsig, cp); - PUTSHORT(ns_c_any, cp); - PUTLONG(0, cp); /*%< TTL */ - lenp = cp; - cp += 2; - - /* Alg. */ - n = dn_comp(NS_TSIG_ALG_HMAC_MD5, cp, eob - cp, NULL, NULL); - if (n < 0) - return (NS_TSIG_ERROR_NO_SPACE); - cp += n; - - /* Time. */ - BOUNDS_CHECK(cp, INT16SZ + INT32SZ + INT16SZ); - PUTSHORT(0, cp); - timesigned = time(NULL); - PUTLONG(timesigned, cp); - PUTSHORT(NS_TSIG_FUDGE, cp); - - /* - * Compute the signature. - */ - - /* Digest the time signed and fudge. */ - cp2 = buf; - PUTSHORT(0, cp2); /*%< Top 16 bits of time */ - PUTLONG(timesigned, cp2); - PUTSHORT(NS_TSIG_FUDGE, cp2); - - dst_sign_data(SIG_MODE_UPDATE, state->key, &state->ctx, - buf, cp2 - buf, NULL, 0); - - n = dst_sign_data(SIG_MODE_FINAL, state->key, &state->ctx, NULL, 0, - state->sig, sizeof(state->sig)); - if (n < 0) - return (-ns_r_badkey); - state->siglen = n; - - /* Add the signature. */ - BOUNDS_CHECK(cp, INT16SZ + state->siglen); - PUTSHORT(state->siglen, cp); - memcpy(cp, state->sig, state->siglen); - cp += state->siglen; - - /* The original message ID & error. */ - BOUNDS_CHECK(cp, INT16SZ + INT16SZ); - PUTSHORT(ntohs(hp->id), cp); /*%< already in network order */ - PUTSHORT(error, cp); - - /* Other data. */ - BOUNDS_CHECK(cp, INT16SZ); - PUTSHORT(0, cp); - - /* Go back and fill in the length. */ - PUTSHORT(cp - lenp - INT16SZ, lenp); - - hp->arcount = htons(ntohs(hp->arcount) + 1); - *msglen = (cp - msg); - return (0); -} - -/*! \file */ diff -pruN /home/reed/src/isc/libbind/libbind/nameser/ns_ttl.c /usr/src/lib/libc/nameser/ns_ttl.c --- /home/reed/src/isc/libbind/libbind/nameser/ns_ttl.c 2005-07-28 01:51:49.000000000 -0500 +++ /usr/src/lib/libc/nameser/ns_ttl.c 2013-06-05 09:26:12.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: ns_ttl.c,v 1.8 2012/03/13 21:13:39 christos Exp $ */ + /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. @@ -15,8 +17,13 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #ifndef lint -static const char rcsid[] = "$Id: ns_ttl.c,v 1.4 2005/07/28 06:51:49 marka Exp $"; +#ifdef notdef +static const char rcsid[] = "Id: ns_ttl.c,v 1.4 2005/07/28 06:51:49 marka Exp"; +#else +__RCSID("$NetBSD: ns_ttl.c,v 1.8 2012/03/13 21:13:39 christos Exp $"); +#endif #endif /* Import. */ @@ -25,6 +32,7 @@ static const char rcsid[] = "$Id: ns_ttl #include +#include #include #include #include @@ -44,7 +52,7 @@ static int fmt1(int t, char s, char **bu /* Macros. */ -#define T(x) if ((x) < 0) return (-1); else (void)NULL +#define T(x) if ((x) < 0) return (-1) /* Public. */ @@ -54,11 +62,11 @@ ns_format_ttl(u_long src, char *dst, siz int secs, mins, hours, days, weeks, x; char *p; - secs = src % 60; src /= 60; - mins = src % 60; src /= 60; - hours = src % 24; src /= 24; - days = src % 7; src /= 7; - weeks = src; src = 0; + secs = (int)(src % 60); src /= 60; + mins = (int)(src % 60); src /= 60; + hours = (int)(src % 24); src /= 24; + days = (int)(src % 7); src /= 7; + weeks = (int)src; src = 0; x = 0; if (weeks) { @@ -90,9 +98,11 @@ ns_format_ttl(u_long src, char *dst, siz *p = tolower(ch); } - return (dst - odst); + _DIAGASSERT(__type_fit(int, dst - odst)); + return (int)(dst - odst); } +#ifndef _LIBC int ns_parse_ttl(const char *src, u_long *dst) { u_long ttl, tmp; @@ -116,10 +126,10 @@ ns_parse_ttl(const char *src, u_long *ds if (islower(ch)) ch = toupper(ch); switch (ch) { - case 'W': tmp *= 7; - case 'D': tmp *= 24; - case 'H': tmp *= 60; - case 'M': tmp *= 60; + case 'W': tmp *= 7; /*FALLTHROUGH*/ + case 'D': tmp *= 24; /*FALLTHROUGH*/ + case 'H': tmp *= 60; /*FALLTHROUGH*/ + case 'M': tmp *= 60; /*FALLTHROUGH*/ case 'S': break; default: goto einval; } @@ -142,6 +152,7 @@ ns_parse_ttl(const char *src, u_long *ds errno = EINVAL; return (-1); } +#endif /* Private. */ diff -pruN /home/reed/src/isc/libbind/libbind/nameser/ns_verify.c /usr/src/lib/libc/nameser/ns_verify.c --- /home/reed/src/isc/libbind/libbind/nameser/ns_verify.c 2006-03-09 17:57:56.000000000 -0600 +++ /usr/src/lib/libc/nameser/ns_verify.c 1969-12-31 18:00:00.000000000 -0600 @@ -1,484 +0,0 @@ -/* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1999 by Internet Software Consortium, Inc. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef lint -static const char rcsid[] = "$Id: ns_verify.c,v 1.5 2006/03/09 23:57:56 marka Exp $"; -#endif - -/* Import. */ - -#include "port_before.h" -#include "fd_setsize.h" - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "port_after.h" - -/* Private. */ - -#define BOUNDS_CHECK(ptr, count) \ - do { \ - if ((ptr) + (count) > eom) { \ - return (NS_TSIG_ERROR_FORMERR); \ - } \ - } while (0) - -/* Public. */ - -u_char * -ns_find_tsig(u_char *msg, u_char *eom) { - HEADER *hp = (HEADER *)msg; - int n, type; - u_char *cp = msg, *start; - - if (msg == NULL || eom == NULL || msg > eom) - return (NULL); - - if (cp + HFIXEDSZ >= eom) - return (NULL); - - if (hp->arcount == 0) - return (NULL); - - cp += HFIXEDSZ; - - n = ns_skiprr(cp, eom, ns_s_qd, ntohs(hp->qdcount)); - if (n < 0) - return (NULL); - cp += n; - - n = ns_skiprr(cp, eom, ns_s_an, ntohs(hp->ancount)); - if (n < 0) - return (NULL); - cp += n; - - n = ns_skiprr(cp, eom, ns_s_ns, ntohs(hp->nscount)); - if (n < 0) - return (NULL); - cp += n; - - n = ns_skiprr(cp, eom, ns_s_ar, ntohs(hp->arcount) - 1); - if (n < 0) - return (NULL); - cp += n; - - start = cp; - n = dn_skipname(cp, eom); - if (n < 0) - return (NULL); - cp += n; - if (cp + INT16SZ >= eom) - return (NULL); - - GETSHORT(type, cp); - if (type != ns_t_tsig) - return (NULL); - return (start); -} - -/* ns_verify - * - * Parameters: - *\li statp res stuff - *\li msg received message - *\li msglen length of message - *\li key tsig key used for verifying. - *\li querysig (response), the signature in the query - *\li querysiglen (response), the length of the signature in the query - *\li sig (query), a buffer to hold the signature - *\li siglen (query), input - length of signature buffer - * output - length of signature - * - * Errors: - *\li - bad input (-1) - *\li - invalid dns message (NS_TSIG_ERROR_FORMERR) - *\li - TSIG is not present (NS_TSIG_ERROR_NO_TSIG) - *\li - key doesn't match (-ns_r_badkey) - *\li - TSIG verification fails with BADKEY (-ns_r_badkey) - *\li - TSIG verification fails with BADSIG (-ns_r_badsig) - *\li - TSIG verification fails with BADTIME (-ns_r_badtime) - *\li - TSIG verification succeeds, error set to BAKEY (ns_r_badkey) - *\li - TSIG verification succeeds, error set to BADSIG (ns_r_badsig) - *\li - TSIG verification succeeds, error set to BADTIME (ns_r_badtime) - */ -int -ns_verify(u_char *msg, int *msglen, void *k, - const u_char *querysig, int querysiglen, u_char *sig, int *siglen, - time_t *timesigned, int nostrip) -{ - HEADER *hp = (HEADER *)msg; - DST_KEY *key = (DST_KEY *)k; - u_char *cp = msg, *eom; - char name[MAXDNAME], alg[MAXDNAME]; - u_char *recstart, *rdatastart; - u_char *sigstart, *otherstart; - int n; - int error; - u_int16_t type, length; - u_int16_t fudge, sigfieldlen, otherfieldlen; - - dst_init(); - if (msg == NULL || msglen == NULL || *msglen < 0) - return (-1); - - eom = msg + *msglen; - - recstart = ns_find_tsig(msg, eom); - if (recstart == NULL) - return (NS_TSIG_ERROR_NO_TSIG); - - cp = recstart; - - /* Read the key name. */ - n = dn_expand(msg, eom, cp, name, MAXDNAME); - if (n < 0) - return (NS_TSIG_ERROR_FORMERR); - cp += n; - - /* Read the type. */ - BOUNDS_CHECK(cp, 2*INT16SZ + INT32SZ + INT16SZ); - GETSHORT(type, cp); - if (type != ns_t_tsig) - return (NS_TSIG_ERROR_NO_TSIG); - - /* Skip the class and TTL, save the length. */ - cp += INT16SZ + INT32SZ; - GETSHORT(length, cp); - if (eom - cp != length) - return (NS_TSIG_ERROR_FORMERR); - - /* Read the algorithm name. */ - rdatastart = cp; - n = dn_expand(msg, eom, cp, alg, MAXDNAME); - if (n < 0) - return (NS_TSIG_ERROR_FORMERR); - if (ns_samename(alg, NS_TSIG_ALG_HMAC_MD5) != 1) - return (-ns_r_badkey); - cp += n; - - /* Read the time signed and fudge. */ - BOUNDS_CHECK(cp, INT16SZ + INT32SZ + INT16SZ); - cp += INT16SZ; - GETLONG((*timesigned), cp); - GETSHORT(fudge, cp); - - /* Read the signature. */ - BOUNDS_CHECK(cp, INT16SZ); - GETSHORT(sigfieldlen, cp); - BOUNDS_CHECK(cp, sigfieldlen); - sigstart = cp; - cp += sigfieldlen; - - /* Skip id and read error. */ - BOUNDS_CHECK(cp, 2*INT16SZ); - cp += INT16SZ; - GETSHORT(error, cp); - - /* Parse the other data. */ - BOUNDS_CHECK(cp, INT16SZ); - GETSHORT(otherfieldlen, cp); - BOUNDS_CHECK(cp, otherfieldlen); - otherstart = cp; - cp += otherfieldlen; - - if (cp != eom) - return (NS_TSIG_ERROR_FORMERR); - - /* Verify that the key used is OK. */ - if (key != NULL) { - if (key->dk_alg != KEY_HMAC_MD5) - return (-ns_r_badkey); - if (error != ns_r_badsig && error != ns_r_badkey) { - if (ns_samename(key->dk_key_name, name) != 1) - return (-ns_r_badkey); - } - } - - hp->arcount = htons(ntohs(hp->arcount) - 1); - - /* - * Do the verification. - */ - - if (key != NULL && error != ns_r_badsig && error != ns_r_badkey) { - void *ctx; - u_char buf[MAXDNAME]; - u_char buf2[MAXDNAME]; - - /* Digest the query signature, if this is a response. */ - dst_verify_data(SIG_MODE_INIT, key, &ctx, NULL, 0, NULL, 0); - if (querysiglen > 0 && querysig != NULL) { - u_int16_t len_n = htons(querysiglen); - dst_verify_data(SIG_MODE_UPDATE, key, &ctx, - (u_char *)&len_n, INT16SZ, NULL, 0); - dst_verify_data(SIG_MODE_UPDATE, key, &ctx, - querysig, querysiglen, NULL, 0); - } - - /* Digest the message. */ - dst_verify_data(SIG_MODE_UPDATE, key, &ctx, msg, recstart - msg, - NULL, 0); - - /* Digest the key name. */ - n = ns_name_pton(name, buf2, sizeof(buf2)); - if (n < 0) - return (-1); - n = ns_name_ntol(buf2, buf, sizeof(buf)); - if (n < 0) - return (-1); - dst_verify_data(SIG_MODE_UPDATE, key, &ctx, buf, n, NULL, 0); - - /* Digest the class and TTL. */ - dst_verify_data(SIG_MODE_UPDATE, key, &ctx, - recstart + dn_skipname(recstart, eom) + INT16SZ, - INT16SZ + INT32SZ, NULL, 0); - - /* Digest the algorithm. */ - n = ns_name_pton(alg, buf2, sizeof(buf2)); - if (n < 0) - return (-1); - n = ns_name_ntol(buf2, buf, sizeof(buf)); - if (n < 0) - return (-1); - dst_verify_data(SIG_MODE_UPDATE, key, &ctx, buf, n, NULL, 0); - - /* Digest the time signed and fudge. */ - dst_verify_data(SIG_MODE_UPDATE, key, &ctx, - rdatastart + dn_skipname(rdatastart, eom), - INT16SZ + INT32SZ + INT16SZ, NULL, 0); - - /* Digest the error and other data. */ - dst_verify_data(SIG_MODE_UPDATE, key, &ctx, - otherstart - INT16SZ - INT16SZ, - otherfieldlen + INT16SZ + INT16SZ, NULL, 0); - - n = dst_verify_data(SIG_MODE_FINAL, key, &ctx, NULL, 0, - sigstart, sigfieldlen); - - if (n < 0) - return (-ns_r_badsig); - - if (sig != NULL && siglen != NULL) { - if (*siglen < sigfieldlen) - return (NS_TSIG_ERROR_NO_SPACE); - memcpy(sig, sigstart, sigfieldlen); - *siglen = sigfieldlen; - } - } else { - if (sigfieldlen > 0) - return (NS_TSIG_ERROR_FORMERR); - if (sig != NULL && siglen != NULL) - *siglen = 0; - } - - /* Reset the counter, since we still need to check for badtime. */ - hp->arcount = htons(ntohs(hp->arcount) + 1); - - /* Verify the time. */ - if (abs((*timesigned) - time(NULL)) > fudge) - return (-ns_r_badtime); - - if (nostrip == 0) { - *msglen = recstart - msg; - hp->arcount = htons(ntohs(hp->arcount) - 1); - } - - if (error != NOERROR) - return (error); - - return (0); -} - -int -ns_verify_tcp_init(void *k, const u_char *querysig, int querysiglen, - ns_tcp_tsig_state *state) -{ - dst_init(); - if (state == NULL || k == NULL || querysig == NULL || querysiglen < 0) - return (-1); - state->counter = -1; - state->key = k; - if (state->key->dk_alg != KEY_HMAC_MD5) - return (-ns_r_badkey); - if (querysiglen > (int)sizeof(state->sig)) - return (-1); - memcpy(state->sig, querysig, querysiglen); - state->siglen = querysiglen; - return (0); -} - -int -ns_verify_tcp(u_char *msg, int *msglen, ns_tcp_tsig_state *state, - int required) -{ - HEADER *hp = (HEADER *)msg; - u_char *recstart, *sigstart; - unsigned int sigfieldlen, otherfieldlen; - u_char *cp, *eom, *cp2; - char name[MAXDNAME], alg[MAXDNAME]; - u_char buf[MAXDNAME]; - int n, type, length, fudge, error; - time_t timesigned; - - if (msg == NULL || msglen == NULL || state == NULL) - return (-1); - - eom = msg + *msglen; - - state->counter++; - if (state->counter == 0) - return (ns_verify(msg, msglen, state->key, - state->sig, state->siglen, - state->sig, &state->siglen, ×igned, 0)); - - if (state->siglen > 0) { - u_int16_t siglen_n = htons(state->siglen); - - dst_verify_data(SIG_MODE_INIT, state->key, &state->ctx, - NULL, 0, NULL, 0); - dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx, - (u_char *)&siglen_n, INT16SZ, NULL, 0); - dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx, - state->sig, state->siglen, NULL, 0); - state->siglen = 0; - } - - cp = recstart = ns_find_tsig(msg, eom); - - if (recstart == NULL) { - if (required) - return (NS_TSIG_ERROR_NO_TSIG); - dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx, - msg, *msglen, NULL, 0); - return (0); - } - - hp->arcount = htons(ntohs(hp->arcount) - 1); - dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx, - msg, recstart - msg, NULL, 0); - - /* Read the key name. */ - n = dn_expand(msg, eom, cp, name, MAXDNAME); - if (n < 0) - return (NS_TSIG_ERROR_FORMERR); - cp += n; - - /* Read the type. */ - BOUNDS_CHECK(cp, 2*INT16SZ + INT32SZ + INT16SZ); - GETSHORT(type, cp); - if (type != ns_t_tsig) - return (NS_TSIG_ERROR_NO_TSIG); - - /* Skip the class and TTL, save the length. */ - cp += INT16SZ + INT32SZ; - GETSHORT(length, cp); - if (eom - cp != length) - return (NS_TSIG_ERROR_FORMERR); - - /* Read the algorithm name. */ - n = dn_expand(msg, eom, cp, alg, MAXDNAME); - if (n < 0) - return (NS_TSIG_ERROR_FORMERR); - if (ns_samename(alg, NS_TSIG_ALG_HMAC_MD5) != 1) - return (-ns_r_badkey); - cp += n; - - /* Verify that the key used is OK. */ - if ((ns_samename(state->key->dk_key_name, name) != 1 || - state->key->dk_alg != KEY_HMAC_MD5)) - return (-ns_r_badkey); - - /* Read the time signed and fudge. */ - BOUNDS_CHECK(cp, INT16SZ + INT32SZ + INT16SZ); - cp += INT16SZ; - GETLONG(timesigned, cp); - GETSHORT(fudge, cp); - - /* Read the signature. */ - BOUNDS_CHECK(cp, INT16SZ); - GETSHORT(sigfieldlen, cp); - BOUNDS_CHECK(cp, sigfieldlen); - sigstart = cp; - cp += sigfieldlen; - - /* Skip id and read error. */ - BOUNDS_CHECK(cp, 2*INT16SZ); - cp += INT16SZ; - GETSHORT(error, cp); - - /* Parse the other data. */ - BOUNDS_CHECK(cp, INT16SZ); - GETSHORT(otherfieldlen, cp); - BOUNDS_CHECK(cp, otherfieldlen); - cp += otherfieldlen; - - if (cp != eom) - return (NS_TSIG_ERROR_FORMERR); - - /* - * Do the verification. - */ - - /* Digest the time signed and fudge. */ - cp2 = buf; - PUTSHORT(0, cp2); /*%< Top 16 bits of time. */ - PUTLONG(timesigned, cp2); - PUTSHORT(NS_TSIG_FUDGE, cp2); - - dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx, - buf, cp2 - buf, NULL, 0); - - n = dst_verify_data(SIG_MODE_FINAL, state->key, &state->ctx, NULL, 0, - sigstart, sigfieldlen); - if (n < 0) - return (-ns_r_badsig); - - if (sigfieldlen > sizeof(state->sig)) - return (NS_TSIG_ERROR_NO_SPACE); - - memcpy(state->sig, sigstart, sigfieldlen); - state->siglen = sigfieldlen; - - /* Verify the time. */ - if (abs(timesigned - time(NULL)) > fudge) - return (-ns_r_badtime); - - *msglen = recstart - msg; - - if (error != NOERROR) - return (error); - - return (0); -} - -/*! \file */