diff options
author | Stuart Henderson <sthen@cvs.openbsd.org> | 2014-03-16 11:38:28 +0000 |
---|---|---|
committer | Stuart Henderson <sthen@cvs.openbsd.org> | 2014-03-16 11:38:28 +0000 |
commit | 4dc35b48dc1c78f151b12012649fd013ceb2fa17 (patch) | |
tree | 282cb435744d12e25316568f6007e5f1b08a7fd4 | |
parent | b7d057e23cd1dd6b391e1c8c29ae824e92456e10 (diff) |
import unbound 1.4.22 upstream sources, ok brad@
-rw-r--r-- | usr.sbin/unbound/ldns/keyraw.c | 6 | ||||
-rw-r--r-- | usr.sbin/unbound/ldns/parseutil.c | 12 | ||||
-rw-r--r-- | usr.sbin/unbound/ldns/rrdef.c | 8 | ||||
-rw-r--r-- | usr.sbin/unbound/ldns/rrdef.h | 6 | ||||
-rw-r--r-- | usr.sbin/unbound/ldns/sbuffer.c | 11 | ||||
-rw-r--r-- | usr.sbin/unbound/ldns/sbuffer.h | 8 | ||||
-rw-r--r-- | usr.sbin/unbound/ldns/str2wire.c | 96 | ||||
-rw-r--r-- | usr.sbin/unbound/ldns/wire2str.c | 8 |
8 files changed, 73 insertions, 82 deletions
diff --git a/usr.sbin/unbound/ldns/keyraw.c b/usr.sbin/unbound/ldns/keyraw.c index 1ff07742b88..fe650aadacb 100644 --- a/usr.sbin/unbound/ldns/keyraw.c +++ b/usr.sbin/unbound/ldns/keyraw.c @@ -324,10 +324,8 @@ sldns_ecdsa2pkey_raw(unsigned char* key, size_t keylen, uint8_t algo) ec = EC_KEY_new_by_curve_name(NID_secp384r1); } else ec = NULL; if(!ec) return NULL; - if(keylen+1 > sizeof(buf)) { /* sanity check */ - EC_KEY_free(ec); - return NULL; - } + if(keylen+1 > sizeof(buf)) + return NULL; /* sanity check */ /* prepend the 0x02 (from docs) (or actually 0x04 from implementation * of openssl) for uncompressed data */ buf[0] = POINT_CONVERSION_UNCOMPRESSED; diff --git a/usr.sbin/unbound/ldns/parseutil.c b/usr.sbin/unbound/ldns/parseutil.c index 28b344ede74..55e3a5b1ad9 100644 --- a/usr.sbin/unbound/ldns/parseutil.c +++ b/usr.sbin/unbound/ldns/parseutil.c @@ -288,9 +288,9 @@ sldns_parse_escape(uint8_t *ch_p, const char** str_p) { uint16_t val; - if ((*str_p)[0] && isdigit((unsigned char)(*str_p)[0]) && - (*str_p)[1] && isdigit((unsigned char)(*str_p)[1]) && - (*str_p)[2] && isdigit((unsigned char)(*str_p)[2])) { + if ((*str_p)[0] && isdigit((*str_p)[0]) && + (*str_p)[1] && isdigit((*str_p)[1]) && + (*str_p)[2] && isdigit((*str_p)[2])) { val = (uint16_t)(((*str_p)[0] - '0') * 100 + ((*str_p)[1] - '0') * 10 + @@ -303,7 +303,7 @@ sldns_parse_escape(uint8_t *ch_p, const char** str_p) *str_p += 3; return 1; - } else if ((*str_p)[0] && !isdigit((unsigned char)(*str_p)[0])) { + } else if ((*str_p)[0] && !isdigit((*str_p)[0])) { *ch_p = (uint8_t)*(*str_p)++; return 1; @@ -467,7 +467,7 @@ sldns_b32_pton_base(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz, ch = *src++; --src_sz; - } while (isspace((unsigned char)ch) && src_sz > 0); + } while (isspace(ch) && src_sz > 0); if (ch == '=' || ch == '\0') break; @@ -572,7 +572,7 @@ sldns_b32_pton_base(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz, ch = *src++; src_sz--; - } while (isspace((unsigned char)ch)); + } while (isspace(ch)); if (ch != '=') return -1; diff --git a/usr.sbin/unbound/ldns/rrdef.c b/usr.sbin/unbound/ldns/rrdef.c index 9b4bf7cfe32..8f7dd3036ec 100644 --- a/usr.sbin/unbound/ldns/rrdef.c +++ b/usr.sbin/unbound/ldns/rrdef.c @@ -359,10 +359,14 @@ static sldns_rr_descriptor rdata_field_descriptors[] = { /* 58 */ {LDNS_RR_TYPE_TALINK, "TALINK", 2, 2, type_talink_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 2 }, +#ifdef DRAFT_RRTYPES /* 59 */ {LDNS_RR_TYPE_CDS, "CDS", 4, 4, type_ds_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, - /* 60 */ - {LDNS_RR_TYPE_CDNSKEY, "CDNSKEY", 4, 4, type_dnskey_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, +#else +{LDNS_RR_TYPE_NULL, "TYPE59", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, +#endif + +{LDNS_RR_TYPE_NULL, "TYPE60", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, {LDNS_RR_TYPE_NULL, "TYPE61", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, {LDNS_RR_TYPE_NULL, "TYPE62", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, {LDNS_RR_TYPE_NULL, "TYPE63", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, diff --git a/usr.sbin/unbound/ldns/rrdef.h b/usr.sbin/unbound/ldns/rrdef.h index 933bcdfbf07..442eb26e0e0 100644 --- a/usr.sbin/unbound/ldns/rrdef.h +++ b/usr.sbin/unbound/ldns/rrdef.h @@ -191,8 +191,8 @@ enum sldns_enum_rr_type LDNS_RR_TYPE_RKEY = 57, /** draft-ietf-dnsop-trust-history */ LDNS_RR_TYPE_TALINK = 58, - LDNS_RR_TYPE_CDS = 59, /** RFC 7344 */ - LDNS_RR_TYPE_CDNSKEY = 60, /** RFC 7344 */ + /** draft-barwood-dnsop-ds-publis */ + LDNS_RR_TYPE_CDS = 59, LDNS_RR_TYPE_SPF = 99, /* RFC 4408 */ @@ -419,7 +419,7 @@ enum sldns_enum_edns_option LDNS_EDNS_N3U = 7, /* RFC6975 */ LDNS_EDNS_CLIENT_SUBNET = 8 /* draft-vandergaast-edns-client-subnet */ }; -typedef enum sldns_enum_edns_option sldns_edns_option; +typedef enum sldns_edns_option sldns_edns_option; #define LDNS_EDNS_MASK_DO_BIT 0x8000 diff --git a/usr.sbin/unbound/ldns/sbuffer.c b/usr.sbin/unbound/ldns/sbuffer.c index 3d087bfe252..b0b2efdcf4f 100644 --- a/usr.sbin/unbound/ldns/sbuffer.c +++ b/usr.sbin/unbound/ldns/sbuffer.c @@ -165,6 +165,17 @@ sldns_buffer_export(sldns_buffer *buffer) return buffer->_data; } +int +sldns_bgetc(sldns_buffer *buffer) +{ + if (!sldns_buffer_available_at(buffer, buffer->_position, sizeof(uint8_t))) { + sldns_buffer_set_position(buffer, sldns_buffer_limit(buffer)); + /* sldns_buffer_rewind(buffer);*/ + return EOF; + } + return (int)sldns_buffer_read_u8(buffer); +} + void sldns_buffer_copy(sldns_buffer* result, sldns_buffer* from) { diff --git a/usr.sbin/unbound/ldns/sbuffer.h b/usr.sbin/unbound/ldns/sbuffer.h index 3ce874fc7f7..2436763d3ea 100644 --- a/usr.sbin/unbound/ldns/sbuffer.h +++ b/usr.sbin/unbound/ldns/sbuffer.h @@ -35,9 +35,9 @@ INLINE uint16_t sldns_read_uint16(const void *src) { #ifdef ALLOW_UNALIGNED_ACCESSES - return ntohs(*(const uint16_t *) src); + return ntohs(*(uint16_t *) src); #else - const uint8_t *p = (const uint8_t *) src; + uint8_t *p = (uint8_t *) src; return ((uint16_t) p[0] << 8) | (uint16_t) p[1]; #endif } @@ -46,9 +46,9 @@ INLINE uint32_t sldns_read_uint32(const void *src) { #ifdef ALLOW_UNALIGNED_ACCESSES - return ntohl(*(const uint32_t *) src); + return ntohl(*(uint32_t *) src); #else - const uint8_t *p = (const uint8_t *) src; + uint8_t *p = (uint8_t *) src; return ( ((uint32_t) p[0] << 24) | ((uint32_t) p[1] << 16) | ((uint32_t) p[2] << 8) diff --git a/usr.sbin/unbound/ldns/str2wire.c b/usr.sbin/unbound/ldns/str2wire.c index 931e28f84e3..92eefa8518f 100644 --- a/usr.sbin/unbound/ldns/str2wire.c +++ b/usr.sbin/unbound/ldns/str2wire.c @@ -245,7 +245,7 @@ rrinternal_get_ttl(sldns_buffer* strbuf, char* token, size_t token_len, } *ttl = (uint32_t) sldns_str2period(token, &endptr); - if (strlen(token) > 0 && !isdigit((unsigned char)token[0])) { + if (strlen(token) > 0 && !isdigit((int)token[0])) { *not_there = 1; /* ah, it's not there or something */ if (default_ttl == 0) { @@ -337,7 +337,7 @@ rrinternal_get_delims(sldns_rdf_type rdftype, uint16_t r_cnt, uint16_t r_max) case LDNS_RDF_TYPE_WKS : /* it is the last rd field. */ case LDNS_RDF_TYPE_IPSECKEY : case LDNS_RDF_TYPE_NSEC : if (r_cnt == r_max - 1) { - return "\n"; + return "\n\t"; } break; default : break; @@ -384,11 +384,11 @@ rrinternal_spool_hex(char* token, uint8_t* rr, size_t rr_len, { char* p = token; while(*p) { - if(isspace((unsigned char)*p)) { + if(isspace(*p)) { p++; continue; } - if(!isxdigit((unsigned char)*p)) + if(!isxdigit(*p)) return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_RDATA, p-token); if(*cur_hex_data_size >= hex_data_size) @@ -827,20 +827,6 @@ const char* sldns_get_errorstr_parse(int e) return lt?lt->name:"unknown error"; } -/* Strip whitespace from the start and the end of <line>. */ -static char * -sldns_strip_ws(char *line) -{ - char *s = line, *e; - - for (s = line; *s && isspace((unsigned char)*s); s++) - ; - for (e = strchr(s, 0); e > s+2 && isspace((unsigned char)e[-1]) && e[-2] != '\\'; e--) - ; - *e = 0; - return s; -} - int sldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len, struct sldns_file_parse_state* parse_state) { @@ -866,23 +852,28 @@ int sldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len, return LDNS_WIREPARSE_ERR_OK; } - if(strncmp(line, "$ORIGIN", 7) == 0 && isspace((unsigned char)line[7])) { + if(strncmp(line, "$ORIGIN", 7) == 0 && isspace(line[7])) { + size_t off = 8; int s; *len = 0; *dname_len = 0; if(!parse_state) return LDNS_WIREPARSE_ERR_OK; + while(isspace(line[off])) + off++; parse_state->origin_len = sizeof(parse_state->origin); - s = sldns_str2wire_dname_buf(sldns_strip_ws(line+8), - parse_state->origin, &parse_state->origin_len); + s = sldns_str2wire_dname_buf(line+off, parse_state->origin, + &parse_state->origin_len); if(s) parse_state->origin_len = 0; return s; - } else if(strncmp(line, "$TTL", 4) == 0 && isspace((unsigned char)line[4])) { + } else if(strncmp(line, "$TTL", 4) == 0 && isspace(line[4])) { const char* end = NULL; + size_t off = 8; *len = 0; *dname_len = 0; if(!parse_state) return LDNS_WIREPARSE_ERR_OK; - parse_state->default_ttl = sldns_str2period( - sldns_strip_ws(line+5), &end); + while(isspace(line[off])) + off++; + parse_state->default_ttl = sldns_str2period(line+off, &end); } else if (strncmp(line, "$INCLUDE", 8) == 0) { *len = 0; *dname_len = 0; @@ -1197,11 +1188,11 @@ int sldns_str2wire_hex_buf(const char* str, uint8_t* rd, size_t* len) const char* s = str; size_t dlen = 0; /* number of hexdigits parsed */ while(*s) { - if(isspace((unsigned char)*s)) { + if(isspace(*s)) { s++; continue; } - if(!isxdigit((unsigned char)*s)) + if(!isxdigit(*s)) return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str); if(*len < dlen/2 + 1) return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, @@ -1401,7 +1392,7 @@ static int loc_parse_cm(char* my_str, char** endstr, uint8_t* m, uint8_t* e) { uint32_t meters = 0, cm = 0, val; - while (isblank((unsigned char)*my_str)) { + while (isblank(*my_str)) { my_str++; } meters = (uint32_t)strtol(my_str, &my_str, 10); @@ -1452,17 +1443,17 @@ int sldns_str2wire_loc_buf(const char* str, uint8_t* rd, size_t* len) char *my_str = (char *) str; - if (isdigit((unsigned char) *my_str)) { + if (isdigit((int) *my_str)) { h = (uint32_t) strtol(my_str, &my_str, 10); } else { return LDNS_WIREPARSE_ERR_INVALID_STR; } - while (isblank((unsigned char) *my_str)) { + while (isblank((int) *my_str)) { my_str++; } - if (isdigit((unsigned char) *my_str)) { + if (isdigit((int) *my_str)) { m = (uint32_t) strtol(my_str, &my_str, 10); } else if (*my_str == 'N' || *my_str == 'S') { goto north; @@ -1470,16 +1461,16 @@ int sldns_str2wire_loc_buf(const char* str, uint8_t* rd, size_t* len) return LDNS_WIREPARSE_ERR_INVALID_STR; } - while (isblank((unsigned char) *my_str)) { + while (isblank((int) *my_str)) { my_str++; } - if (isdigit((unsigned char) *my_str)) { + if (isdigit((int) *my_str)) { s = strtod(my_str, &my_str); } /* skip blanks before norterness */ - while (isblank((unsigned char) *my_str)) { + while (isblank((int) *my_str)) { my_str++; } @@ -1506,21 +1497,21 @@ north: } else { latitude = equator - latitude; } - while (isblank((unsigned char)*my_str)) { + while (isblank(*my_str)) { my_str++; } - if (isdigit((unsigned char) *my_str)) { + if (isdigit((int) *my_str)) { h = (uint32_t) strtol(my_str, &my_str, 10); } else { return LDNS_WIREPARSE_ERR_INVALID_STR; } - while (isblank((unsigned char) *my_str)) { + while (isblank((int) *my_str)) { my_str++; } - if (isdigit((unsigned char) *my_str)) { + if (isdigit((int) *my_str)) { m = (uint32_t) strtol(my_str, &my_str, 10); } else if (*my_str == 'E' || *my_str == 'W') { goto east; @@ -1528,16 +1519,16 @@ north: return LDNS_WIREPARSE_ERR_INVALID_STR; } - while (isblank((unsigned char)*my_str)) { + while (isblank(*my_str)) { my_str++; } - if (isdigit((unsigned char) *my_str)) { + if (isdigit((int) *my_str)) { s = strtod(my_str, &my_str); } /* skip blanks before easterness */ - while (isblank((unsigned char)*my_str)) { + while (isblank(*my_str)) { my_str++; } @@ -1600,17 +1591,6 @@ east: return LDNS_WIREPARSE_ERR_OK; } -static void -ldns_tolower_str(char* s) -{ - if(s) { - while(*s) { - *s = (char)tolower((unsigned char)*s); - s++; - } - } -} - int sldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len) { int rd_len = 1; @@ -1625,7 +1605,6 @@ int sldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len) return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL; while(sldns_bget_token(&strbuf, token, "\t\n ", sizeof(token)) > 0) { - ldns_tolower_str(token); if(!have_proto) { struct protoent *p = getprotobyname(token); have_proto = 1; @@ -1703,11 +1682,11 @@ int sldns_str2wire_nsap_buf(const char* str, uint8_t* rd, size_t* len) if(slen > LDNS_MAX_RDFLEN*2) return LDNS_WIREPARSE_ERR_LABEL_OVERFLOW; while(*s) { - if(isspace((unsigned char)*s) || *s == '.') { + if(isspace(*s) || *s == '.') { s++; continue; } - if(!isxdigit((unsigned char)*s)) + if(!isxdigit(*s)) return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str); if(*len < dlen/2 + 1) return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, @@ -1734,11 +1713,11 @@ int sldns_str2wire_atma_buf(const char* str, uint8_t* rd, size_t* len) if(slen > LDNS_MAX_RDFLEN*2) return LDNS_WIREPARSE_ERR_LABEL_OVERFLOW; while(*s) { - if(isspace((unsigned char)*s) || *s == '.') { + if(isspace(*s) || *s == '.') { s++; continue; } - if(!isxdigit((unsigned char)*s)) + if(!isxdigit(*s)) return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str); if(*len < dlen/2 + 1) return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, @@ -1841,8 +1820,7 @@ int sldns_str2wire_nsec3_salt_buf(const char* str, uint8_t* rd, size_t* len) return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL; rd[0] = (uint8_t) (salt_length_str / 2); for (i = 0; i < salt_length_str; i += 2) { - if (isxdigit((unsigned char)str[i]) && - isxdigit((unsigned char)str[i+1])) { + if (isxdigit((int)str[i]) && isxdigit((int)str[i+1])) { rd[1+i/2] = (uint8_t)(sldns_hexdigit_to_int(str[i])*16 + sldns_hexdigit_to_int(str[i+1])); } else { @@ -1929,7 +1907,7 @@ int sldns_str2wire_tag_buf(const char* str, uint8_t* rd, size_t* len) if(*len < slen+1) return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL; for (ptr = str; *ptr; ptr++) { - if(!isalnum((unsigned char)*ptr)) + if(!isalnum(*ptr)) return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_TAG, ptr-str); } rd[0] = slen; diff --git a/usr.sbin/unbound/ldns/wire2str.c b/usr.sbin/unbound/ldns/wire2str.c index 81e173c78d5..c2a1850ef9b 100644 --- a/usr.sbin/unbound/ldns/wire2str.c +++ b/usr.sbin/unbound/ldns/wire2str.c @@ -722,7 +722,7 @@ static int dname_char_print(char** s, size_t* slen, uint8_t c) { if(c == '.' || c == ';' || c == '(' || c == ')' || c == '\\') return sldns_str_print(s, slen, "\\%c", c); - else if(!(isascii((unsigned char)c) && isgraph((unsigned char)c))) + else if(!(isascii((int)c) && isgraph((int)c))) return sldns_str_print(s, slen, "\\%03u", (unsigned)c); /* plain printout */ if(*slen) { @@ -1064,7 +1064,7 @@ int sldns_wire2str_aaaa_scan(uint8_t** d, size_t* dl, char** s, size_t* sl) /** printout escaped TYPE_STR character */ static int str_char_print(char** s, size_t* sl, uint8_t c) { - if(isprint((unsigned char)c) || c == '\t') { + if(isprint((int)c) || c == '\t') { if(c == '\"' || c == '\\') return sldns_str_print(s, sl, "\\%c", c); if(*sl) { @@ -1625,7 +1625,7 @@ int sldns_wire2str_tag_scan(uint8_t** d, size_t* dl, char** s, size_t* sl) if(*dl < 1+n) return -1; for(i=0; i<n; i++) - if(!isalnum((unsigned char)(*d)[i])) + if(!isalnum((int)(*d)[i])) return -1; for(i=0; i<n; i++) w += sldns_str_print(s, sl, "%c", (char)(*d)[i]); @@ -1713,7 +1713,7 @@ int sldns_wire2str_edns_nsid_print(char** s, size_t* sl, uint8_t* data, size_t i, printed=0; w += print_hex_buf(s, sl, data, len); for(i=0; i<len; i++) { - if(isprint((unsigned char)data[i]) || data[i] == '\t') { + if(isprint((int)data[i]) || data[i] == '\t') { if(!printed) { w += sldns_str_print(s, sl, " ("); printed = 1; |