From: tcarpay <8014108+TCY16@users.noreply.github.com> Date: Fri, 2 Jul 2021 11:14:47 +0000 (+0200) Subject: Apply suggestions from code review X-Git-Tag: release-1.13.2rc1~42^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=877aa8df55bea67dac6b66cbe2435bfbe93a09a3;p=thirdparty%2Funbound.git Apply suggestions from code review Co-authored-by: Willem Toorop --- diff --git a/sldns/str2wire.c b/sldns/str2wire.c index 9f94f69cd..55c38e12d 100644 --- a/sldns/str2wire.c +++ b/sldns/str2wire.c @@ -853,7 +853,7 @@ rrinternal_parse_rdata(sldns_buffer* strbuf, char* token, size_t token_len, } /* The root label is one more character, so smaller * than 1 + 1 means no Svcparam Keys */ - if (rdata_len < 2) + if (rdata_len < 2 || *rdata != 0) return LDNS_WIREPARSE_ERR_OK; rdata_len -= 1; @@ -1348,26 +1348,26 @@ sldns_str2wire_svcbparam_mandatory(const char* val, uint8_t* rd, size_t* rd_len) * So long as we do not distinguish between running Unbound as a primary * or as a secondary, we default to secondary behavior and we ignore the * semantic errors. */ - +#ifdef SVCB_SEMANTIC_ERRORS /* In draft-ietf-dnsop-svcb-https-06 Section 8 * automatically mandatory MUST NOT appear in its own value-list */ - // if (sldns_read_uint16(rd + 4) == SVCB_KEY_MANDATORY) - // return LDNS_WIREPARSE_ERR_SVCB_MANDATORY_IN_MANDATORY; + if (sldns_read_uint16(rd + 4) == SVCB_KEY_MANDATORY) + return LDNS_WIREPARSE_ERR_SVCB_MANDATORY_IN_MANDATORY; /* Guarantee key uniqueness. After the sort we only need to * compare neighbouring keys */ - // if (count > 1) { - // for (i = 0; i < count - 1; i++) { - // uint8_t* current_pos = (rd + 4 + (sizeof(uint16_t) * i)); - // uint16_t key = sldns_read_uint16(current_pos); - - // if (key == sldns_read_uint16(current_pos + 2)) { - // return LDNS_WIREPARSE_ERR_SVCB_MANDATORY_DUPLICATE_KEY; - // } - // } - // } + if (count > 1) { + for (i = 0; i < count - 1; i++) { + uint8_t* current_pos = (rd + 4 + (sizeof(uint16_t) * i)); + uint16_t key = sldns_read_uint16(current_pos); + if (key == sldns_read_uint16(current_pos + 2)) { + return LDNS_WIREPARSE_ERR_SVCB_MANDATORY_DUPLICATE_KEY; + } + } + } +#endif return LDNS_WIREPARSE_ERR_OK; } diff --git a/sldns/wire2str.c b/sldns/wire2str.c index 5bfa9f43d..6a177ec0b 100644 --- a/sldns/wire2str.c +++ b/sldns/wire2str.c @@ -989,7 +989,6 @@ static int sldns_wire2str_svcparam_port2str(char** s, if (data_len != 2) return -1; /* wireformat error, a short is 2 bytes */ w = sldns_str_print(s, slen, "=%d", (int)sldns_read_uint16(data)); - data += 2; return w; }