From: Willem Toorop Date: Tue, 25 May 2021 13:56:19 +0000 (+0200) Subject: Fix mandatory parsing and ech printing X-Git-Tag: release-1.13.2rc1~42^2~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=956d7d4e44f15dd53241e3e15c60d91af79743e8;p=thirdparty%2Funbound.git Fix mandatory parsing and ech printing --- diff --git a/sldns/str2wire.c b/sldns/str2wire.c index 1b09766bc..df244910e 100644 --- a/sldns/str2wire.c +++ b/sldns/str2wire.c @@ -1168,8 +1168,8 @@ sldns_str2wire_svcbparam_mandatory(const char* val, uint8_t* rd, size_t* rd_len) return -1; } } - - // @TODO check if we have space to write in rd_len; look for the best spot + if (sizeof(uint16_t) * (count + 2) > *rd_len) + return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL; sldns_write_uint16(rd, SVCB_KEY_MANDATORY); sldns_write_uint16(rd + 2, sizeof(uint16_t) * count); @@ -1179,12 +1179,12 @@ sldns_str2wire_svcbparam_mandatory(const char* val, uint8_t* rd, size_t* rd_len) if (!(next_key = strchr(val, ','))) { sldns_write_uint16(rd + *rd_len, sldns_str2wire_svcparam_key_lookup(val, val_len)); - *rd_len += LDNS_IP6ADDRLEN; + *rd_len += 2; break; } else { sldns_write_uint16(rd + *rd_len, sldns_str2wire_svcparam_key_lookup(val, next_key - val)); - *rd_len += LDNS_IP6ADDRLEN; + *rd_len += 2; } val_len -= next_key - val + 1; diff --git a/sldns/wire2str.c b/sldns/wire2str.c index f6c32cfe3..07a4911c4 100644 --- a/sldns/wire2str.c +++ b/sldns/wire2str.c @@ -1091,14 +1091,14 @@ static int sldns_wire2str_svcparam_ech2str(char** s, size_t* slen, uint16_t data_len, uint8_t* data) { int size; - int w; + int w = 0; assert(data_len > 0); /* Guaranteed by rdata_svcparam_to_string */ w += sldns_str_print(s, slen, "=\""); /* b64_ntop_calculate size includes null at the end */ - size = sldns_b64_ntop_calculate_size(data_len); + size = sldns_b64_ntop_calculate_size(data_len) - 1; // @TODO store return value? sldns_b64_ntop(data, data_len, *s, *slen);