Bring gldns in sync with upstream unbound's sldns

This commit is contained in:
Willem Toorop 2016-01-05 14:17:28 +01:00
parent 6dba2b98a0
commit 4d67db5b83
11 changed files with 142 additions and 85 deletions

21
src/gldns/compare.sh Executable file
View File

@ -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/<ldns\/rrdef\.h>/"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/<gldns\/rrdef\.h>/<sldns\/rrdef.h>/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

View File

@ -35,9 +35,9 @@ INLINE uint16_t
gldns_read_uint16(const void *src) gldns_read_uint16(const void *src)
{ {
#ifdef ALLOW_UNALIGNED_ACCESSES #ifdef ALLOW_UNALIGNED_ACCESSES
return ntohs(*(uint16_t *) src); return ntohs(*(const uint16_t *) src);
#else #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]; return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
#endif #endif
} }
@ -46,9 +46,9 @@ INLINE uint32_t
gldns_read_uint32(const void *src) gldns_read_uint32(const void *src)
{ {
#ifdef ALLOW_UNALIGNED_ACCESSES #ifdef ALLOW_UNALIGNED_ACCESSES
return ntohl(*(uint32_t *) src); return ntohl(*(const uint32_t *) src);
#else #else
uint8_t *p = (uint8_t *) src; const uint8_t *p = (const uint8_t *) src;
return ( ((uint32_t) p[0] << 24) return ( ((uint32_t) p[0] << 24)
| ((uint32_t) p[1] << 16) | ((uint32_t) p[1] << 16)
| ((uint32_t) p[2] << 8) | ((uint32_t) p[2] << 8)
@ -366,7 +366,6 @@ gldns_buffer_end(gldns_buffer *buffer)
INLINE uint8_t * INLINE uint8_t *
gldns_buffer_current(gldns_buffer *buffer) gldns_buffer_current(gldns_buffer *buffer)
{ {
assert(buffer->_position <= buffer->_limit || buffer->_fixed);
return gldns_buffer_at(buffer, buffer->_position); return gldns_buffer_at(buffer, buffer->_position);
} }

View File

@ -2,11 +2,30 @@
# Meant to be run from this directory # Meant to be run from this directory
svn co http://unbound.net/svn/trunk/ldns/ if [ -d gldns ]
for f in ldns/*.[ch] then
do # Import synchronised files from comparison directory
sed -e 's/sldns_/gldns_/g' -e 's/LDNS_/GLDNS_/g' -e 's/include "ldns/include "gldns/g' -e 's/<ldns\/rrdef\.h>/"gldns\/rrdef.h"/g' -e 's/sbuffer\.h/gbuffer.h/g' $f > ${f#ldns/} for f in gldns/*.[ch]
done do
mv sbuffer.h gbuffer.h sed -e 's/sldns_/gldns_/g' \
mv sbuffer.c gbuffer.c -e 's/LDNS_/GLDNS_/g' \
rm -r ldns -e 's/include "sldns/include "gldns/g' \
-e 's/<sldns\/rrdef\.h>/<gldns\/rrdef.h>/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/<sldns\/rrdef\.h>/<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
fi

View File

@ -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); ec = EC_KEY_new_by_curve_name(NID_secp384r1);
} else ec = NULL; } else ec = NULL;
if(!ec) return NULL; if(!ec) return NULL;
if(keylen+1 > sizeof(buf)) if(keylen+1 > sizeof(buf)) { /* sanity check */
return NULL; /* sanity check */ EC_KEY_free(ec);
return NULL;
}
/* prepend the 0x02 (from docs) (or actually 0x04 from implementation /* prepend the 0x02 (from docs) (or actually 0x04 from implementation
* of openssl) for uncompressed data */ * of openssl) for uncompressed data */
buf[0] = POINT_CONVERSION_UNCOMPRESSED; buf[0] = POINT_CONVERSION_UNCOMPRESSED;

View File

@ -14,7 +14,6 @@
#include "config.h" #include "config.h"
#include "gldns/parseutil.h" #include "gldns/parseutil.h"
#include <strings.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <ctype.h> #include <ctype.h>
@ -289,9 +288,9 @@ gldns_parse_escape(uint8_t *ch_p, const char** str_p)
{ {
uint16_t val; uint16_t val;
if ((*str_p)[0] && isdigit((*str_p)[0]) && if ((*str_p)[0] && isdigit((unsigned char)(*str_p)[0]) &&
(*str_p)[1] && isdigit((*str_p)[1]) && (*str_p)[1] && isdigit((unsigned char)(*str_p)[1]) &&
(*str_p)[2] && isdigit((*str_p)[2])) { (*str_p)[2] && isdigit((unsigned char)(*str_p)[2])) {
val = (uint16_t)(((*str_p)[0] - '0') * 100 + val = (uint16_t)(((*str_p)[0] - '0') * 100 +
((*str_p)[1] - '0') * 10 + ((*str_p)[1] - '0') * 10 +
@ -304,7 +303,7 @@ gldns_parse_escape(uint8_t *ch_p, const char** str_p)
*str_p += 3; *str_p += 3;
return 1; 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)++; *ch_p = (uint8_t)*(*str_p)++;
return 1; return 1;
@ -468,7 +467,7 @@ gldns_b32_pton_base(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz,
ch = *src++; ch = *src++;
--src_sz; --src_sz;
} while (isspace(ch) && src_sz > 0); } while (isspace((unsigned char)ch) && src_sz > 0);
if (ch == '=' || ch == '\0') if (ch == '=' || ch == '\0')
break; 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++; ch = *src++;
src_sz--; src_sz--;
} while (isspace(ch)); } while (isspace((unsigned char)ch));
if (ch != '=') if (ch != '=')
return -1; return -1;

View File

@ -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 * 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. * That number of seconds is then converted to broken-out time information.
* This is especially usefull when converting the inception and expiration * This is especially usefull when converting the inception and expiration
* fields of RRSIG records. * fields of RRSIG records.
* *
* \param[in] time number of seconds since epoch (midnight, January 1st, 1970) * \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) * \param[in] now number of seconds since epoch (midnight, January 1st, 1970)
* to which the time value is compared to determine the final value. * to which the time value is compared to determine the final value.
* \param[out] result the struct with the broken-out time information * \param[out] result the struct with the broken-out time information

View File

@ -15,7 +15,6 @@
#include "config.h" #include "config.h"
#include "gldns/rrdef.h" #include "gldns/rrdef.h"
#include "gldns/parseutil.h" #include "gldns/parseutil.h"
#include <strings.h>
/* classes */ /* classes */
static gldns_lookup_table gldns_rr_classes_data[] = { static gldns_lookup_table gldns_rr_classes_data[] = {
@ -214,13 +213,11 @@ static const gldns_rdf_type type_eui48_wireformat[] = {
static const gldns_rdf_type type_eui64_wireformat[] = { static const gldns_rdf_type type_eui64_wireformat[] = {
GLDNS_RDF_TYPE_EUI64 GLDNS_RDF_TYPE_EUI64
}; };
#ifdef DRAFT_RRTYPES
static const gldns_rdf_type type_uri_wireformat[] = { static const gldns_rdf_type type_uri_wireformat[] = {
GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_INT16,
GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_INT16,
GLDNS_RDF_TYPE_LONG_STR GLDNS_RDF_TYPE_LONG_STR
}; };
#endif
static const gldns_rdf_type type_caa_wireformat[] = { static const gldns_rdf_type type_caa_wireformat[] = {
GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_INT8,
GLDNS_RDF_TYPE_TAG, GLDNS_RDF_TYPE_TAG,
@ -591,12 +588,8 @@ static gldns_rr_descriptor rdata_field_descriptors[] = {
/* ANY: A request for all (available) records */ /* 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 }, {GLDNS_RR_TYPE_ANY, "ANY", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
#ifdef DRAFT_RRTYPES
/* 256 */ /* 256 */
{GLDNS_RR_TYPE_URI, "URI", 3, 3, type_uri_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 }, {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 */ /* 257 */
{GLDNS_RR_TYPE_CAA, "CAA", 3, 3, type_caa_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 }, {GLDNS_RR_TYPE_CAA, "CAA", 3, 3, type_caa_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },

View File

@ -220,8 +220,7 @@ enum gldns_enum_rr_type
GLDNS_RR_TYPE_MAILA = 254, GLDNS_RR_TYPE_MAILA = 254,
/** any type (wildcard) */ /** any type (wildcard) */
GLDNS_RR_TYPE_ANY = 255, GLDNS_RR_TYPE_ANY = 255,
/** draft-faltstrom-uri-06 */ GLDNS_RR_TYPE_URI = 256, /* RFC 7553 */
GLDNS_RR_TYPE_URI = 256,
GLDNS_RR_TYPE_CAA = 257, /* RFC 6844 */ GLDNS_RR_TYPE_CAA = 257, /* RFC 6844 */
/** DNSSEC Trust Authorities */ /** DNSSEC Trust Authorities */
@ -343,7 +342,7 @@ enum gldns_enum_rdf_type
/** A <character-string> encoding of the value field as specified /** A <character-string> encoding of the value field as specified
* [RFC1035], Section 5.1., encoded as remaining rdata. * [RFC1035], Section 5.1., encoded as remaining rdata.
* For CAA. * For CAA, URI.
*/ */
GLDNS_RDF_TYPE_LONG_STR, GLDNS_RDF_TYPE_LONG_STR,

View File

@ -245,7 +245,7 @@ rrinternal_get_ttl(gldns_buffer* strbuf, char* token, size_t token_len,
} }
*ttl = (uint32_t) gldns_str2period(token, &endptr); *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; *not_there = 1;
/* ah, it's not there or something */ /* ah, it's not there or something */
if (default_ttl == 0) { 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_WKS : /* it is the last rd field. */
case GLDNS_RDF_TYPE_IPSECKEY : case GLDNS_RDF_TYPE_IPSECKEY :
case GLDNS_RDF_TYPE_NSEC : if (r_cnt == r_max - 1) { case GLDNS_RDF_TYPE_NSEC : if (r_cnt == r_max - 1) {
return "\n\t"; return "\n";
} }
break; break;
default : break; default : break;
@ -384,11 +384,11 @@ rrinternal_spool_hex(char* token, uint8_t* rr, size_t rr_len,
{ {
char* p = token; char* p = token;
while(*p) { while(*p) {
if(isspace(*p)) { if(isspace((unsigned char)*p)) {
p++; p++;
continue; continue;
} }
if(!isxdigit(*p)) if(!isxdigit((unsigned char)*p))
return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_RDATA, return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_RDATA,
p-token); p-token);
if(*cur_hex_data_size >= hex_data_size) 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"; return lt?lt->name:"unknown error";
} }
/* Strip whitespace from the start and the end of <line>. */
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, int gldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len,
struct gldns_file_parse_state* parse_state) 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; return GLDNS_WIREPARSE_ERR_OK;
} }
if(strncmp(line, "$ORIGIN", 7) == 0 && isspace(line[7])) { if(strncmp(line, "$ORIGIN", 7) == 0 && isspace((unsigned char)line[7])) {
size_t off = 8;
int s; int s;
*len = 0; *len = 0;
*dname_len = 0; *dname_len = 0;
if(!parse_state) return GLDNS_WIREPARSE_ERR_OK; if(!parse_state) return GLDNS_WIREPARSE_ERR_OK;
while(isspace(line[off]))
off++;
parse_state->origin_len = sizeof(parse_state->origin); parse_state->origin_len = sizeof(parse_state->origin);
s = gldns_str2wire_dname_buf(line+off, parse_state->origin, s = gldns_str2wire_dname_buf(gldns_strip_ws(line+8),
&parse_state->origin_len); parse_state->origin, &parse_state->origin_len);
if(s) parse_state->origin_len = 0; if(s) parse_state->origin_len = 0;
return s; 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; const char* end = NULL;
size_t off = 5;
*len = 0; *len = 0;
*dname_len = 0; *dname_len = 0;
if(!parse_state) return GLDNS_WIREPARSE_ERR_OK; if(!parse_state) return GLDNS_WIREPARSE_ERR_OK;
while(isspace(line[off])) parse_state->default_ttl = gldns_str2period(
off++; gldns_strip_ws(line+5), &end);
parse_state->default_ttl = gldns_str2period(line+off, &end);
} else if (strncmp(line, "$INCLUDE", 8) == 0) { } else if (strncmp(line, "$INCLUDE", 8) == 0) {
*len = 0; *len = 0;
*dname_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; const char* s = str;
size_t dlen = 0; /* number of hexdigits parsed */ size_t dlen = 0; /* number of hexdigits parsed */
while(*s) { while(*s) {
if(isspace(*s)) { if(isspace((unsigned char)*s)) {
s++; s++;
continue; continue;
} }
if(!isxdigit(*s)) if(!isxdigit((unsigned char)*s))
return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str); return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str);
if(*len < dlen/2 + 1) if(*len < dlen/2 + 1)
return RET_ERR(GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, 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) loc_parse_cm(char* my_str, char** endstr, uint8_t* m, uint8_t* e)
{ {
uint32_t meters = 0, cm = 0, val; uint32_t meters = 0, cm = 0, val;
while (isblank(*my_str)) { while (isblank((unsigned char)*my_str)) {
my_str++; my_str++;
} }
meters = (uint32_t)strtol(my_str, &my_str, 10); 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; 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); h = (uint32_t) strtol(my_str, &my_str, 10);
} else { } else {
return GLDNS_WIREPARSE_ERR_INVALID_STR; return GLDNS_WIREPARSE_ERR_INVALID_STR;
} }
while (isblank((int) *my_str)) { while (isblank((unsigned char) *my_str)) {
my_str++; my_str++;
} }
if (isdigit((int) *my_str)) { if (isdigit((unsigned char) *my_str)) {
m = (uint32_t) strtol(my_str, &my_str, 10); m = (uint32_t) strtol(my_str, &my_str, 10);
} else if (*my_str == 'N' || *my_str == 'S') { } else if (*my_str == 'N' || *my_str == 'S') {
goto north; 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; return GLDNS_WIREPARSE_ERR_INVALID_STR;
} }
while (isblank((int) *my_str)) { while (isblank((unsigned char) *my_str)) {
my_str++; my_str++;
} }
if (isdigit((int) *my_str)) { if (isdigit((unsigned char) *my_str)) {
s = strtod(my_str, &my_str); s = strtod(my_str, &my_str);
} }
/* skip blanks before norterness */ /* skip blanks before norterness */
while (isblank((int) *my_str)) { while (isblank((unsigned char) *my_str)) {
my_str++; my_str++;
} }
@ -1497,21 +1506,21 @@ north:
} else { } else {
latitude = equator - latitude; latitude = equator - latitude;
} }
while (isblank(*my_str)) { while (isblank((unsigned char)*my_str)) {
my_str++; my_str++;
} }
if (isdigit((int) *my_str)) { if (isdigit((unsigned char) *my_str)) {
h = (uint32_t) strtol(my_str, &my_str, 10); h = (uint32_t) strtol(my_str, &my_str, 10);
} else { } else {
return GLDNS_WIREPARSE_ERR_INVALID_STR; return GLDNS_WIREPARSE_ERR_INVALID_STR;
} }
while (isblank((int) *my_str)) { while (isblank((unsigned char) *my_str)) {
my_str++; my_str++;
} }
if (isdigit((int) *my_str)) { if (isdigit((unsigned char) *my_str)) {
m = (uint32_t) strtol(my_str, &my_str, 10); m = (uint32_t) strtol(my_str, &my_str, 10);
} else if (*my_str == 'E' || *my_str == 'W') { } else if (*my_str == 'E' || *my_str == 'W') {
goto east; goto east;
@ -1519,16 +1528,16 @@ north:
return GLDNS_WIREPARSE_ERR_INVALID_STR; return GLDNS_WIREPARSE_ERR_INVALID_STR;
} }
while (isblank(*my_str)) { while (isblank((unsigned char)*my_str)) {
my_str++; my_str++;
} }
if (isdigit((int) *my_str)) { if (isdigit((unsigned char) *my_str)) {
s = strtod(my_str, &my_str); s = strtod(my_str, &my_str);
} }
/* skip blanks before easterness */ /* skip blanks before easterness */
while (isblank(*my_str)) { while (isblank((unsigned char)*my_str)) {
my_str++; my_str++;
} }
@ -1591,6 +1600,17 @@ east:
return GLDNS_WIREPARSE_ERR_OK; 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 gldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len)
{ {
int rd_len = 1; 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; return GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
while(gldns_bget_token(&strbuf, token, "\t\n ", sizeof(token)) > 0) { while(gldns_bget_token(&strbuf, token, "\t\n ", sizeof(token)) > 0) {
ldns_tolower_str(token);
if(!have_proto) { if(!have_proto) {
struct protoent *p = getprotobyname(token); struct protoent *p = getprotobyname(token);
have_proto = 1; 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) if(slen > GLDNS_MAX_RDFLEN*2)
return GLDNS_WIREPARSE_ERR_LABEL_OVERFLOW; return GLDNS_WIREPARSE_ERR_LABEL_OVERFLOW;
while(*s) { while(*s) {
if(isspace(*s) || *s == '.') { if(isspace((unsigned char)*s) || *s == '.') {
s++; s++;
continue; continue;
} }
if(!isxdigit(*s)) if(!isxdigit((unsigned char)*s))
return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str); return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str);
if(*len < dlen/2 + 1) if(*len < dlen/2 + 1)
return RET_ERR(GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, 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) if(slen > GLDNS_MAX_RDFLEN*2)
return GLDNS_WIREPARSE_ERR_LABEL_OVERFLOW; return GLDNS_WIREPARSE_ERR_LABEL_OVERFLOW;
while(*s) { while(*s) {
if(isspace(*s) || *s == '.') { if(isspace((unsigned char)*s) || *s == '.') {
s++; s++;
continue; continue;
} }
if(!isxdigit(*s)) if(!isxdigit((unsigned char)*s))
return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str); return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str);
if(*len < dlen/2 + 1) if(*len < dlen/2 + 1)
return RET_ERR(GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, 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; return GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
rd[0] = (uint8_t) (salt_length_str / 2); rd[0] = (uint8_t) (salt_length_str / 2);
for (i = 0; i < salt_length_str; i += 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 rd[1+i/2] = (uint8_t)(gldns_hexdigit_to_int(str[i])*16
+ gldns_hexdigit_to_int(str[i+1])); + gldns_hexdigit_to_int(str[i+1]));
} else { } else {
@ -1907,7 +1929,7 @@ int gldns_str2wire_tag_buf(const char* str, uint8_t* rd, size_t* len)
if(*len < slen+1) if(*len < slen+1)
return GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL; return GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
for (ptr = str; *ptr; ptr++) { for (ptr = str; *ptr; ptr++) {
if(!isalnum(*ptr)) if(!isalnum((unsigned char)*ptr))
return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_TAG, ptr-str); return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_TAG, ptr-str);
} }
rd[0] = slen; rd[0] = slen;

View File

@ -16,7 +16,7 @@
#define GLDNS_STR2WIRE_H #define GLDNS_STR2WIRE_H
/* include rrdef for MAX_DOMAINLEN constant */ /* include rrdef for MAX_DOMAINLEN constant */
#include "gldns/rrdef.h" #include <gldns/rrdef.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -698,6 +698,9 @@ int gldns_wire2str_rdata_scan(uint8_t** d, size_t* dlen, char** s,
} }
w += n; w += n;
} }
if(*dlen != 0) {
goto failed;
}
return w; 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 == '\\') if(c == '.' || c == ';' || c == '(' || c == ')' || c == '\\')
return gldns_str_print(s, slen, "\\%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); return gldns_str_print(s, slen, "\\%03u", (unsigned)c);
/* plain printout */ /* plain printout */
if(*slen) { 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 */ /** printout escaped TYPE_STR character */
static int str_char_print(char** s, size_t* sl, uint8_t c) 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 == '\\') if(c == '\"' || c == '\\')
return gldns_str_print(s, sl, "\\%c", c); return gldns_str_print(s, sl, "\\%c", c);
if(*sl) { 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) if(*dl < 1+n)
return -1; return -1;
for(i=0; i<n; i++) for(i=0; i<n; i++)
if(!isalnum((int)(*d)[i])) if(!isalnum((unsigned char)(*d)[i]))
return -1; return -1;
for(i=0; i<n; i++) for(i=0; i<n; i++)
w += gldns_str_print(s, sl, "%c", (char)(*d)[i]); w += gldns_str_print(s, sl, "%c", (char)(*d)[i]);
@ -1714,7 +1717,7 @@ int gldns_wire2str_edns_nsid_print(char** s, size_t* sl, uint8_t* data,
size_t i, printed=0; size_t i, printed=0;
w += print_hex_buf(s, sl, data, len); w += print_hex_buf(s, sl, data, len);
for(i=0; i<len; i++) { for(i=0; i<len; i++) {
if(isprint((int)data[i]) || data[i] == '\t') { if(isprint((unsigned char)data[i]) || data[i] == '\t') {
if(!printed) { if(!printed) {
w += gldns_str_print(s, sl, " ("); w += gldns_str_print(s, sl, " (");
printed = 1; printed = 1;