diff --git a/src/gldns/compare.sh b/src/gldns/compare.sh new file mode 100755 index 00000000..415c6bcc --- /dev/null +++ b/src/gldns/compare.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Meant to be run from this directory +rm -fr gldns +mkdir gldns +svn co http://unbound.net/svn/trunk/sldns/ +mv gbuffer.h sbuffer.h +mv gbuffer.c sbuffer.c +for f in sldns/*.[ch] +do +#sed -e 's/sldns_/gldns_/g' -e 's/LDNS_/GLDNS_/g' -e 's/include "ldns/include "gldns/g' -e 's//"gldns\/rrdef.h"/g' -e 's/sbuffer\.h/gbuffer.h/g' ${f#sldns/} > gldns/${f#sldns/} + sed -e 's/gldns_/sldns_/g' \ + -e 's/GLDNS_/LDNS_/g' \ + -e 's///g' \ + -e 's/include "gldns/include "sldns/g' \ + -e 's/gbuffer\.h/sbuffer.h/g' \ + ${f#sldns/} > gldns/${f#sldns/} +done +mv sbuffer.h gbuffer.h +mv sbuffer.c gbuffer.c + diff --git a/src/gldns/gbuffer.h b/src/gldns/gbuffer.h index 333e1176..745bb8eb 100644 --- a/src/gldns/gbuffer.h +++ b/src/gldns/gbuffer.h @@ -35,9 +35,9 @@ INLINE uint16_t gldns_read_uint16(const void *src) { #ifdef ALLOW_UNALIGNED_ACCESSES - return ntohs(*(uint16_t *) src); + return ntohs(*(const uint16_t *) src); #else - uint8_t *p = (uint8_t *) src; + const uint8_t *p = (const uint8_t *) src; return ((uint16_t) p[0] << 8) | (uint16_t) p[1]; #endif } @@ -46,9 +46,9 @@ INLINE uint32_t gldns_read_uint32(const void *src) { #ifdef ALLOW_UNALIGNED_ACCESSES - return ntohl(*(uint32_t *) src); + return ntohl(*(const uint32_t *) src); #else - uint8_t *p = (uint8_t *) src; + const uint8_t *p = (const uint8_t *) src; return ( ((uint32_t) p[0] << 24) | ((uint32_t) p[1] << 16) | ((uint32_t) p[2] << 8) @@ -366,7 +366,6 @@ gldns_buffer_end(gldns_buffer *buffer) INLINE uint8_t * gldns_buffer_current(gldns_buffer *buffer) { - assert(buffer->_position <= buffer->_limit || buffer->_fixed); return gldns_buffer_at(buffer, buffer->_position); } diff --git a/src/gldns/import.sh b/src/gldns/import.sh index c8223903..ce85339c 100755 --- a/src/gldns/import.sh +++ b/src/gldns/import.sh @@ -2,11 +2,30 @@ # Meant to be run from this directory -svn co http://unbound.net/svn/trunk/ldns/ -for f in ldns/*.[ch] -do - sed -e 's/sldns_/gldns_/g' -e 's/LDNS_/GLDNS_/g' -e 's/include "ldns/include "gldns/g' -e 's//"gldns\/rrdef.h"/g' -e 's/sbuffer\.h/gbuffer.h/g' $f > ${f#ldns/} -done -mv sbuffer.h gbuffer.h -mv sbuffer.c gbuffer.c -rm -r ldns +if [ -d gldns ] +then + # Import synchronised files from comparison directory + for f in gldns/*.[ch] + do + sed -e 's/sldns_/gldns_/g' \ + -e 's/LDNS_/GLDNS_/g' \ + -e 's/include "sldns/include "gldns/g' \ + -e 's///g' \ + -e 's/sbuffer\.h/gbuffer.h/g' $f > ${f#gldns/} + done + mv sbuffer.h gbuffer.h + mv sbuffer.c gbuffer.c +else + svn co http://unbound.net/svn/trunk/ldns/ + for f in ldns/*.[ch] + do + sed -e 's/sldns_/gldns_/g' \ + -e 's/LDNS_/GLDNS_/g' \ + -e 's/include "sldns/include "gldns/g' \ + -e 's///g' \ + -e 's/sbuffer\.h/gbuffer.h/g' $f > ${f#ldns/} + done + mv sbuffer.h gbuffer.h + mv sbuffer.c gbuffer.c + rm -r ldns +fi diff --git a/src/gldns/keyraw.c b/src/gldns/keyraw.c index a1bc2719..6b4f4481 100644 --- a/src/gldns/keyraw.c +++ b/src/gldns/keyraw.c @@ -324,8 +324,10 @@ gldns_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)) - return NULL; /* sanity check */ + if(keylen+1 > sizeof(buf)) { /* sanity check */ + EC_KEY_free(ec); + return NULL; + } /* prepend the 0x02 (from docs) (or actually 0x04 from implementation * of openssl) for uncompressed data */ buf[0] = POINT_CONVERSION_UNCOMPRESSED; diff --git a/src/gldns/parseutil.c b/src/gldns/parseutil.c index 1158b2b0..a21567e0 100644 --- a/src/gldns/parseutil.c +++ b/src/gldns/parseutil.c @@ -14,7 +14,6 @@ #include "config.h" #include "gldns/parseutil.h" -#include #include #include #include @@ -52,7 +51,7 @@ static const int mdays[] = { static int is_leap_year(int year) { - return GLDNS_MOD(year, 4) == 0 && (GLDNS_MOD(year, 100) != 0 + return GLDNS_MOD(year, 4) == 0 && (GLDNS_MOD(year, 100) != 0 || GLDNS_MOD(year, 400) == 0); } @@ -61,7 +60,7 @@ leap_days(int y1, int y2) { --y1; --y2; - return (GLDNS_DIV(y2, 4) - GLDNS_DIV(y1, 4)) - + return (GLDNS_DIV(y2, 4) - GLDNS_DIV(y1, 4)) - (GLDNS_DIV(y2, 100) - GLDNS_DIV(y1, 100)) + (GLDNS_DIV(y2, 400) - GLDNS_DIV(y1, 400)); } @@ -121,7 +120,7 @@ static void gldns_mon_and_mday_from_year_and_yday(struct tm *result) { int idays = result->tm_yday; - const int *mon_lengths = is_leap_year(result->tm_year) ? + const int *mon_lengths = is_leap_year(result->tm_year) ? leap_year_mdays : mdays; result->tm_mon = 0; @@ -289,9 +288,9 @@ gldns_parse_escape(uint8_t *ch_p, const char** str_p) { uint16_t val; - if ((*str_p)[0] && isdigit((*str_p)[0]) && - (*str_p)[1] && isdigit((*str_p)[1]) && - (*str_p)[2] && isdigit((*str_p)[2])) { + 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])) { val = (uint16_t)(((*str_p)[0] - '0') * 100 + ((*str_p)[1] - '0') * 10 + @@ -304,7 +303,7 @@ gldns_parse_escape(uint8_t *ch_p, const char** str_p) *str_p += 3; return 1; - } else if ((*str_p)[0] && !isdigit((*str_p)[0])) { + } else if ((*str_p)[0] && !isdigit((unsigned char)(*str_p)[0])) { *ch_p = (uint8_t)*(*str_p)++; return 1; @@ -348,14 +347,14 @@ gldns_b32_ntop_base(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz, const char* b32 = extended_hex ? "0123456789abcdefghijklmnopqrstuv" : "abcdefghijklmnopqrstuvwxyz234567"; - size_t c = 0; /* c is used to carry partial base32 character over + size_t c = 0; /* c is used to carry partial base32 character over * byte boundaries for sizes with a remainder. * (i.e. src_sz % 5 != 0) */ ret_sz = add_padding ? gldns_b32_ntop_calculate_size(src_sz) : gldns_b32_ntop_calculate_size_no_padding(src_sz); - + /* Do we have enough space? */ if (dst_sz < ret_sz + 1) return -1; @@ -433,13 +432,13 @@ gldns_b32_ntop_base(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz, return (int)ret_sz; } -int +int gldns_b32_ntop(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz) { return gldns_b32_ntop_base(src, src_sz, dst, dst_sz, 0, 1); } -int +int gldns_b32_ntop_extended_hex(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz) { @@ -468,7 +467,7 @@ gldns_b32_pton_base(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz, ch = *src++; --src_sz; - } while (isspace(ch) && src_sz > 0); + } while (isspace((unsigned char)ch) && src_sz > 0); if (ch == '=' || ch == '\0') break; @@ -573,7 +572,7 @@ gldns_b32_pton_base(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz, ch = *src++; src_sz--; - } while (isspace(ch)); + } while (isspace((unsigned char)ch)); if (ch != '=') return -1; @@ -590,7 +589,7 @@ gldns_b32_pton(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz) } int -gldns_b32_pton_extended_hex(const char* src, size_t src_sz, +gldns_b32_pton_extended_hex(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz) { return gldns_b32_pton_base(src, src_sz, dst, dst_sz, 1, 1); diff --git a/src/gldns/parseutil.h b/src/gldns/parseutil.h index d4a03ad3..b2b6101d 100644 --- a/src/gldns/parseutil.h +++ b/src/gldns/parseutil.h @@ -56,13 +56,13 @@ time_t gldns_mktime_from_utc(const struct tm *tm); /** * The function interprets time as the number of seconds since epoch - * with respect to now using serial arithmitics (rfc1982). + * with respect to now using serial arithmetics (rfc1982). * That number of seconds is then converted to broken-out time information. * This is especially usefull when converting the inception and expiration * fields of RRSIG records. * * \param[in] time number of seconds since epoch (midnight, January 1st, 1970) - * to be intepreted as a serial arithmitics number relative to now. + * to be intepreted as a serial arithmetics number relative to now. * \param[in] now number of seconds since epoch (midnight, January 1st, 1970) * to which the time value is compared to determine the final value. * \param[out] result the struct with the broken-out time information diff --git a/src/gldns/rrdef.c b/src/gldns/rrdef.c index 28237f96..fe409e4a 100644 --- a/src/gldns/rrdef.c +++ b/src/gldns/rrdef.c @@ -15,7 +15,6 @@ #include "config.h" #include "gldns/rrdef.h" #include "gldns/parseutil.h" -#include /* classes */ static gldns_lookup_table gldns_rr_classes_data[] = { @@ -36,7 +35,7 @@ static const gldns_rdf_type type_md_wireformat[] = { GLDNS_RDF_TYPE_DNAME }; static const gldns_rdf_type type_mf_wireformat[] = { GLDNS_RDF_TYPE_DNAME }; static const gldns_rdf_type type_cname_wireformat[] = { GLDNS_RDF_TYPE_DNAME }; static const gldns_rdf_type type_soa_wireformat[] = { - GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_INT32, + GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_INT32, GLDNS_RDF_TYPE_PERIOD, GLDNS_RDF_TYPE_PERIOD, GLDNS_RDF_TYPE_PERIOD, GLDNS_RDF_TYPE_PERIOD }; @@ -214,13 +213,11 @@ static const gldns_rdf_type type_eui48_wireformat[] = { static const gldns_rdf_type type_eui64_wireformat[] = { GLDNS_RDF_TYPE_EUI64 }; -#ifdef DRAFT_RRTYPES static const gldns_rdf_type type_uri_wireformat[] = { GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_LONG_STR }; -#endif static const gldns_rdf_type type_caa_wireformat[] = { GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_TAG, @@ -591,12 +588,8 @@ static gldns_rr_descriptor rdata_field_descriptors[] = { /* ANY: A request for all (available) records */ {GLDNS_RR_TYPE_ANY, "ANY", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 }, -#ifdef DRAFT_RRTYPES /* 256 */ {GLDNS_RR_TYPE_URI, "URI", 3, 3, type_uri_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 }, -#else -{GLDNS_RR_TYPE_NULL, "TYPE256", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 }, -#endif /* 257 */ {GLDNS_RR_TYPE_CAA, "CAA", 3, 3, type_caa_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 }, diff --git a/src/gldns/rrdef.h b/src/gldns/rrdef.h index 3f7035cf..55803cb6 100644 --- a/src/gldns/rrdef.h +++ b/src/gldns/rrdef.h @@ -220,8 +220,7 @@ enum gldns_enum_rr_type GLDNS_RR_TYPE_MAILA = 254, /** any type (wildcard) */ GLDNS_RR_TYPE_ANY = 255, - /** draft-faltstrom-uri-06 */ - GLDNS_RR_TYPE_URI = 256, + GLDNS_RR_TYPE_URI = 256, /* RFC 7553 */ GLDNS_RR_TYPE_CAA = 257, /* RFC 6844 */ /** DNSSEC Trust Authorities */ @@ -343,7 +342,7 @@ enum gldns_enum_rdf_type /** A encoding of the value field as specified * [RFC1035], Section 5.1., encoded as remaining rdata. - * For CAA. + * For CAA, URI. */ GLDNS_RDF_TYPE_LONG_STR, diff --git a/src/gldns/str2wire.c b/src/gldns/str2wire.c index df534806..d662636f 100644 --- a/src/gldns/str2wire.c +++ b/src/gldns/str2wire.c @@ -245,7 +245,7 @@ rrinternal_get_ttl(gldns_buffer* strbuf, char* token, size_t token_len, } *ttl = (uint32_t) gldns_str2period(token, &endptr); - if (strlen(token) > 0 && !isdigit((int)token[0])) { + if (strlen(token) > 0 && !isdigit((unsigned char)token[0])) { *not_there = 1; /* ah, it's not there or something */ if (default_ttl == 0) { @@ -337,7 +337,7 @@ rrinternal_get_delims(gldns_rdf_type rdftype, uint16_t r_cnt, uint16_t r_max) case GLDNS_RDF_TYPE_WKS : /* it is the last rd field. */ case GLDNS_RDF_TYPE_IPSECKEY : case GLDNS_RDF_TYPE_NSEC : if (r_cnt == r_max - 1) { - return "\n\t"; + return "\n"; } 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(*p)) { + if(isspace((unsigned char)*p)) { p++; continue; } - if(!isxdigit(*p)) + if(!isxdigit((unsigned char)*p)) return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_RDATA, p-token); if(*cur_hex_data_size >= hex_data_size) @@ -827,6 +827,20 @@ const char* gldns_get_errorstr_parse(int e) return lt?lt->name:"unknown error"; } +/* Strip whitespace from the start and the end of . */ +static char * +gldns_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 gldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len, struct gldns_file_parse_state* parse_state) { @@ -852,28 +866,23 @@ int gldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len, return GLDNS_WIREPARSE_ERR_OK; } - if(strncmp(line, "$ORIGIN", 7) == 0 && isspace(line[7])) { - size_t off = 8; + if(strncmp(line, "$ORIGIN", 7) == 0 && isspace((unsigned char)line[7])) { int s; *len = 0; *dname_len = 0; if(!parse_state) return GLDNS_WIREPARSE_ERR_OK; - while(isspace(line[off])) - off++; parse_state->origin_len = sizeof(parse_state->origin); - s = gldns_str2wire_dname_buf(line+off, parse_state->origin, - &parse_state->origin_len); + s = gldns_str2wire_dname_buf(gldns_strip_ws(line+8), + parse_state->origin, &parse_state->origin_len); if(s) parse_state->origin_len = 0; return s; - } else if(strncmp(line, "$TTL", 4) == 0 && isspace(line[4])) { + } else if(strncmp(line, "$TTL", 4) == 0 && isspace((unsigned char)line[4])) { const char* end = NULL; - size_t off = 5; *len = 0; *dname_len = 0; if(!parse_state) return GLDNS_WIREPARSE_ERR_OK; - while(isspace(line[off])) - off++; - parse_state->default_ttl = gldns_str2period(line+off, &end); + parse_state->default_ttl = gldns_str2period( + gldns_strip_ws(line+5), &end); } else if (strncmp(line, "$INCLUDE", 8) == 0) { *len = 0; *dname_len = 0; @@ -1188,11 +1197,11 @@ int gldns_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(*s)) { + if(isspace((unsigned char)*s)) { s++; continue; } - if(!isxdigit(*s)) + if(!isxdigit((unsigned char)*s)) return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str); if(*len < dlen/2 + 1) return RET_ERR(GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, @@ -1392,7 +1401,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(*my_str)) { + while (isblank((unsigned char)*my_str)) { my_str++; } meters = (uint32_t)strtol(my_str, &my_str, 10); @@ -1443,17 +1452,17 @@ int gldns_str2wire_loc_buf(const char* str, uint8_t* rd, size_t* len) char *my_str = (char *) str; - if (isdigit((int) *my_str)) { + if (isdigit((unsigned char) *my_str)) { h = (uint32_t) strtol(my_str, &my_str, 10); } else { return GLDNS_WIREPARSE_ERR_INVALID_STR; } - while (isblank((int) *my_str)) { + while (isblank((unsigned char) *my_str)) { my_str++; } - if (isdigit((int) *my_str)) { + if (isdigit((unsigned char) *my_str)) { m = (uint32_t) strtol(my_str, &my_str, 10); } else if (*my_str == 'N' || *my_str == 'S') { goto north; @@ -1461,16 +1470,16 @@ int gldns_str2wire_loc_buf(const char* str, uint8_t* rd, size_t* len) return GLDNS_WIREPARSE_ERR_INVALID_STR; } - while (isblank((int) *my_str)) { + while (isblank((unsigned char) *my_str)) { my_str++; } - if (isdigit((int) *my_str)) { + if (isdigit((unsigned char) *my_str)) { s = strtod(my_str, &my_str); } /* skip blanks before norterness */ - while (isblank((int) *my_str)) { + while (isblank((unsigned char) *my_str)) { my_str++; } @@ -1497,21 +1506,21 @@ north: } else { latitude = equator - latitude; } - while (isblank(*my_str)) { + while (isblank((unsigned char)*my_str)) { my_str++; } - if (isdigit((int) *my_str)) { + if (isdigit((unsigned char) *my_str)) { h = (uint32_t) strtol(my_str, &my_str, 10); } else { return GLDNS_WIREPARSE_ERR_INVALID_STR; } - while (isblank((int) *my_str)) { + while (isblank((unsigned char) *my_str)) { my_str++; } - if (isdigit((int) *my_str)) { + if (isdigit((unsigned char) *my_str)) { m = (uint32_t) strtol(my_str, &my_str, 10); } else if (*my_str == 'E' || *my_str == 'W') { goto east; @@ -1519,16 +1528,16 @@ north: return GLDNS_WIREPARSE_ERR_INVALID_STR; } - while (isblank(*my_str)) { + while (isblank((unsigned char)*my_str)) { my_str++; } - if (isdigit((int) *my_str)) { + if (isdigit((unsigned char) *my_str)) { s = strtod(my_str, &my_str); } /* skip blanks before easterness */ - while (isblank(*my_str)) { + while (isblank((unsigned char)*my_str)) { my_str++; } @@ -1591,6 +1600,17 @@ east: return GLDNS_WIREPARSE_ERR_OK; } +static void +ldns_tolower_str(char* s) +{ + if(s) { + while(*s) { + *s = (char)tolower((unsigned char)*s); + s++; + } + } +} + int gldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len) { int rd_len = 1; @@ -1605,6 +1625,7 @@ int gldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len) return GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL; while(gldns_bget_token(&strbuf, token, "\t\n ", sizeof(token)) > 0) { + ldns_tolower_str(token); if(!have_proto) { struct protoent *p = getprotobyname(token); have_proto = 1; @@ -1682,11 +1703,11 @@ int gldns_str2wire_nsap_buf(const char* str, uint8_t* rd, size_t* len) if(slen > GLDNS_MAX_RDFLEN*2) return GLDNS_WIREPARSE_ERR_LABEL_OVERFLOW; while(*s) { - if(isspace(*s) || *s == '.') { + if(isspace((unsigned char)*s) || *s == '.') { s++; continue; } - if(!isxdigit(*s)) + if(!isxdigit((unsigned char)*s)) return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str); if(*len < dlen/2 + 1) return RET_ERR(GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, @@ -1713,11 +1734,11 @@ int gldns_str2wire_atma_buf(const char* str, uint8_t* rd, size_t* len) if(slen > GLDNS_MAX_RDFLEN*2) return GLDNS_WIREPARSE_ERR_LABEL_OVERFLOW; while(*s) { - if(isspace(*s) || *s == '.') { + if(isspace((unsigned char)*s) || *s == '.') { s++; continue; } - if(!isxdigit(*s)) + if(!isxdigit((unsigned char)*s)) return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str); if(*len < dlen/2 + 1) return RET_ERR(GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, @@ -1820,7 +1841,8 @@ int gldns_str2wire_nsec3_salt_buf(const char* str, uint8_t* rd, size_t* len) return GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL; rd[0] = (uint8_t) (salt_length_str / 2); for (i = 0; i < salt_length_str; i += 2) { - if (isxdigit((int)str[i]) && isxdigit((int)str[i+1])) { + if (isxdigit((unsigned char)str[i]) && + isxdigit((unsigned char)str[i+1])) { rd[1+i/2] = (uint8_t)(gldns_hexdigit_to_int(str[i])*16 + gldns_hexdigit_to_int(str[i+1])); } else { @@ -1907,7 +1929,7 @@ int gldns_str2wire_tag_buf(const char* str, uint8_t* rd, size_t* len) if(*len < slen+1) return GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL; for (ptr = str; *ptr; ptr++) { - if(!isalnum(*ptr)) + if(!isalnum((unsigned char)*ptr)) return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_TAG, ptr-str); } rd[0] = slen; diff --git a/src/gldns/str2wire.h b/src/gldns/str2wire.h index f892f6d1..e9360447 100644 --- a/src/gldns/str2wire.h +++ b/src/gldns/str2wire.h @@ -16,7 +16,7 @@ #define GLDNS_STR2WIRE_H /* include rrdef for MAX_DOMAINLEN constant */ -#include "gldns/rrdef.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/gldns/wire2str.c b/src/gldns/wire2str.c index 0fa1c4cb..f15631b0 100644 --- a/src/gldns/wire2str.c +++ b/src/gldns/wire2str.c @@ -698,6 +698,9 @@ int gldns_wire2str_rdata_scan(uint8_t** d, size_t* dlen, char** s, } w += n; } + if(*dlen != 0) { + goto failed; + } return w; } @@ -723,7 +726,7 @@ static int dname_char_print(char** s, size_t* slen, uint8_t c) { if(c == '.' || c == ';' || c == '(' || c == ')' || c == '\\') return gldns_str_print(s, slen, "\\%c", c); - else if(!(isascii((int)c) && isgraph((int)c))) + else if(!(isascii((unsigned char)c) && isgraph((unsigned char)c))) return gldns_str_print(s, slen, "\\%03u", (unsigned)c); /* plain printout */ if(*slen) { @@ -1065,7 +1068,7 @@ int gldns_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((int)c) || c == '\t') { + if(isprint((unsigned char)c) || c == '\t') { if(c == '\"' || c == '\\') return gldns_str_print(s, sl, "\\%c", c); if(*sl) { @@ -1626,7 +1629,7 @@ int gldns_wire2str_tag_scan(uint8_t** d, size_t* dl, char** s, size_t* sl) if(*dl < 1+n) return -1; for(i=0; i