diff options
Diffstat (limited to 'sldns')
-rw-r--r-- | sldns/parseutil.c | 9 | ||||
-rw-r--r-- | sldns/str2wire.c | 11 | ||||
-rw-r--r-- | sldns/wire2str.c | 10 |
3 files changed, 30 insertions, 0 deletions
diff --git a/sldns/parseutil.c b/sldns/parseutil.c index 32717616aa4a..769987c64777 100644 --- a/sldns/parseutil.c +++ b/sldns/parseutil.c @@ -402,10 +402,12 @@ sldns_b32_ntop_base(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz, /* ........ ........ ....4444 4....... ........ */ c = src[3] >> 7 ; + /* fallthrough */ case 3: dst[4] = b32[(src[2] & 0x0f) << 1 | c]; /* ........ .......3 3333.... ........ ........ */ c = src[2] >> 4 ; + /* fallthrough */ case 2: dst[3] = b32[(src[1] & 0x01) << 4 | c]; /* ........ ..22222. ........ ........ ........ */ @@ -413,6 +415,7 @@ sldns_b32_ntop_base(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz, /* .....111 11...... ........ ........ ........ */ c = src[1] >> 6 ; + /* fallthrough */ case 1: dst[1] = b32[(src[0] & 0x07) << 2 | c]; /* 00000... ........ ........ ........ ........ */ @@ -423,9 +426,12 @@ sldns_b32_ntop_base(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz, switch (src_sz) { case 1: dst[2] = '='; dst[3] = '='; + /* fallthrough */ case 2: dst[4] = '='; + /* fallthrough */ case 3: dst[5] = '='; dst[6] = '='; + /* fallthrough */ case 4: dst[7] = '='; } } @@ -537,15 +543,18 @@ sldns_b32_pton_base(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz, /* ........ ........ ........ .55555.. ........ */ /* ........ ........ ....4444 4....... ........ */ dst[3] = buf[4] << 7 | buf[5] << 2 | buf[6] >> 3; + /* fallthrough */ case 5: /* ........ ........ ....4444 4....... ........ */ /* ........ .......3 3333.... ........ ........ */ dst[2] = buf[3] << 4 | buf[4] >> 1; + /* fallthrough */ case 4: /* ........ .......3 3333.... ........ ........ */ /* ........ ..22222. ........ ........ ........ */ /* .....111 11...... ........ ........ ........ */ dst[1] = buf[1] << 6 | buf[2] << 1 | buf[3] >> 4; + /* fallthrough */ case 2: /* .....111 11...... ........ ........ ........ */ /* 00000... ........ ........ ........ ........ */ diff --git a/sldns/str2wire.c b/sldns/str2wire.c index b4f84faf9b3b..f84d7d6b823b 100644 --- a/sldns/str2wire.c +++ b/sldns/str2wire.c @@ -1190,6 +1190,10 @@ int sldns_str2wire_b64_buf(const char* str, uint8_t* rd, size_t* len) { size_t sz = sldns_b64_pton_calculate_size(strlen(str)); int n; + if(strcmp(str, "0") == 0) { + *len = 0; + return LDNS_WIREPARSE_ERR_OK; + } if(*len < sz) return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL; n = sldns_b64_pton(str, rd, *len); @@ -1223,6 +1227,10 @@ int sldns_str2wire_hex_buf(const char* str, uint8_t* rd, size_t* len) s++; continue; } + if(dlen == 0 && *s == '0' && *(s+1) == 0) { + *len = 0; + return LDNS_WIREPARSE_ERR_OK; + } if(!isxdigit((unsigned char)*s)) return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str); if(*len < dlen/2 + 1) @@ -1685,12 +1693,15 @@ int sldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len) struct protoent *p = getprotobyname(token); have_proto = 1; if(p) rd[0] = (uint8_t)p->p_proto; + else if(strcasecmp(token, "tcp")==0) rd[0]=6; + else if(strcasecmp(token, "udp")==0) rd[0]=17; else rd[0] = (uint8_t)atoi(token); (void)strlcpy(proto_str, token, sizeof(proto_str)); } else { int serv_port; struct servent *serv = getservbyname(token, proto_str); if(serv) serv_port=(int)ntohs((uint16_t)serv->s_port); + else if(strcasecmp(token, "domain")==0) serv_port=53; else { serv_port = atoi(token); if(serv_port == 0 && strcmp(token, "0") != 0) { diff --git a/sldns/wire2str.c b/sldns/wire2str.c index ef505780f454..52b1ed0c2aa9 100644 --- a/sldns/wire2str.c +++ b/sldns/wire2str.c @@ -1220,11 +1220,17 @@ static int sldns_wire2str_b64_scan_num(uint8_t** d, size_t* dl, char** s, int sldns_wire2str_b64_scan(uint8_t** d, size_t* dl, char** s, size_t* sl) { + if(*dl == 0) { + return sldns_str_print(s, sl, "0"); + } return sldns_wire2str_b64_scan_num(d, dl, s, sl, *dl); } int sldns_wire2str_hex_scan(uint8_t** d, size_t* dl, char** s, size_t* sl) { + if(*dl == 0) { + return sldns_str_print(s, sl, "0"); + } return print_remainder_hex("", d, dl, s, sl); } @@ -1465,6 +1471,10 @@ int sldns_wire2str_wks_scan(uint8_t** d, size_t* dl, char** s, size_t* sl) if(protocol && (protocol->p_name != NULL)) { w += sldns_str_print(s, sl, "%s", protocol->p_name); proto_name = protocol->p_name; + } else if(protocol_nr == 6) { + w += sldns_str_print(s, sl, "tcp"); + } else if(protocol_nr == 17) { + w += sldns_str_print(s, sl, "udp"); } else { w += sldns_str_print(s, sl, "%u", (unsigned)protocol_nr); } |