aboutsummaryrefslogtreecommitdiff
path: root/contrib/unbound/util/data
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/unbound/util/data')
-rw-r--r--contrib/unbound/util/data/dname.c44
-rw-r--r--contrib/unbound/util/data/dname.h15
-rw-r--r--contrib/unbound/util/data/msgencode.c6
-rw-r--r--contrib/unbound/util/data/msgencode.h2
-rw-r--r--contrib/unbound/util/data/msgparse.h6
-rw-r--r--contrib/unbound/util/data/msgreply.c27
-rw-r--r--contrib/unbound/util/data/msgreply.h12
7 files changed, 84 insertions, 28 deletions
diff --git a/contrib/unbound/util/data/dname.c b/contrib/unbound/util/data/dname.c
index f08760e2f9fc..5370aa6f9585 100644
--- a/contrib/unbound/util/data/dname.c
+++ b/contrib/unbound/util/data/dname.c
@@ -57,7 +57,7 @@ query_dname_len(sldns_buffer* query)
if(sldns_buffer_remaining(query) < 1)
return 0; /* parse error, need label len */
labellen = sldns_buffer_read_u8(query);
- if(labellen&0xc0)
+ if((labellen&0xc0))
return 0; /* no compression allowed in queries */
len += labellen + 1;
if(len > LDNS_MAX_DOMAINLEN)
@@ -79,7 +79,7 @@ dname_valid(uint8_t* dname, size_t maxlen)
return 0; /* too short, shortest is '0' root label */
labellen = *dname++;
while(labellen) {
- if(labellen&0xc0)
+ if((labellen&0xc0))
return 0; /* no compression ptrs allowed */
len += labellen + 1;
if(len >= LDNS_MAX_DOMAINLEN)
@@ -644,20 +644,22 @@ void dname_str(uint8_t* dname, char* str)
if(!dname || !*dname) {
*s++ = '.';
*s = 0;
- goto out;
+ return;
}
lablen = *dname++;
while(lablen) {
- if(lablen > LDNS_MAX_LABELLEN) {
- *s++ = '#';
- *s = 0;
- goto out;
- }
len += lablen+1;
if(len >= LDNS_MAX_DOMAINLEN) {
+ if ((s-str) >= (LDNS_MAX_DOMAINLEN-1))
+ s = str + LDNS_MAX_DOMAINLEN - 2;
*s++ = '&';
*s = 0;
- goto out;
+ return;
+ }
+ if(lablen > LDNS_MAX_LABELLEN) {
+ *s++ = '#';
+ *s = 0;
+ return;
}
while(lablen--) {
if(isalnum((unsigned char)*dname)
@@ -673,10 +675,6 @@ void dname_str(uint8_t* dname, char* str)
lablen = *dname++;
}
*s = 0;
-
-out:
- log_assert(s - str < LDNS_MAX_DOMAINLEN);
- return;
}
int
@@ -728,7 +726,7 @@ dname_is_root(uint8_t* dname)
return (len == 0);
}
-void
+void
dname_remove_label(uint8_t** dname, size_t* len)
{
size_t lablen;
@@ -742,7 +740,23 @@ dname_remove_label(uint8_t** dname, size_t* len)
*dname += lablen+1;
}
-void
+int
+dname_remove_label_limit_len(uint8_t** dname, size_t* len, size_t lenlimit)
+{
+ size_t lablen;
+ log_assert(dname && *dname && len);
+ lablen = (*dname)[0];
+ log_assert(!LABEL_IS_PTR(lablen));
+ log_assert(*len > lablen);
+ if(lablen == 0)
+ return 0; /* do not modify root label */
+ if(*len - (lablen + 1) < lenlimit) return 0;
+ *len -= lablen+1;
+ *dname += lablen+1;
+ return 1;
+}
+
+void
dname_remove_labels(uint8_t** dname, size_t* len, int n)
{
int i;
diff --git a/contrib/unbound/util/data/dname.h b/contrib/unbound/util/data/dname.h
index 6e4cf7ea3be7..f68c64a03f0d 100644
--- a/contrib/unbound/util/data/dname.h
+++ b/contrib/unbound/util/data/dname.h
@@ -262,11 +262,24 @@ int dname_is_root(uint8_t* dname);
* Snip off first label from a dname, returning the parent zone.
* @param dname: from what to strip off. uncompressed wireformat.
* @param len: length, adjusted to become less.
- * return stripped off, or "." if input was ".".
+ * return dname stripped off, or "." if input was ".".
*/
void dname_remove_label(uint8_t** dname, size_t* len);
/**
+ * Same as dname_remove_label but fails if removal would surpass lenlimit.
+ * If no failure,
+ * snip off first label from a dname, returning the parent zone.
+ * @param dname: from what to strip off. uncompressed wireformat.
+ * @param len: length, adjusted to become less.
+ * @param lenlimit: length limit that we can't surpass (usually the zone apex).
+ * @return
+ * o 1, and dname stripped off, or "." if input was ".", else
+ * o 0, if going up would surpass lenlimit.
+ */
+int dname_remove_label_limit_len(uint8_t** dname, size_t* len, size_t lenlimit);
+
+/**
* Snip off first N labels from a dname, returning the parent zone.
* @param dname: from what to strip off. uncompressed wireformat.
* @param len: length, adjusted to become less.
diff --git a/contrib/unbound/util/data/msgencode.c b/contrib/unbound/util/data/msgencode.c
index 6d116fb52d6d..84aa3b9e75ae 100644
--- a/contrib/unbound/util/data/msgencode.c
+++ b/contrib/unbound/util/data/msgencode.c
@@ -365,7 +365,7 @@ compress_any_dname(uint8_t* dname, sldns_buffer* pkt, int labs,
/** return true if type needs domain name compression in rdata */
static const sldns_rr_descriptor*
-type_rdata_compressable(struct ub_packed_rrset_key* key)
+type_rdata_compressible(struct ub_packed_rrset_key* key)
{
uint16_t t = ntohs(key->rk.type);
if(sldns_rr_descript(t) &&
@@ -486,7 +486,7 @@ packed_rrset_encode(struct ub_packed_rrset_key* key, sldns_buffer* pkt,
adjust = SERVE_ORIGINAL_TTL ? data->ttl_add : timenow;
if(do_data) {
- const sldns_rr_descriptor* c = type_rdata_compressable(key);
+ const sldns_rr_descriptor* c = type_rdata_compressible(key);
for(i=0; i<data->count; i++) {
/* rrset roundrobin */
j = (i + rr_offset) % data->count;
@@ -1021,7 +1021,7 @@ reply_info_answer_encode(struct query_info* qinf, struct reply_info* rep,
flags |= BIT_AA;
flags &= ~BIT_AD;
}
- log_assert(flags & BIT_QR); /* QR bit must be on in our replies */
+ log_assert((flags & BIT_QR)); /* QR bit must be on in our replies */
if(udpsize < LDNS_HEADER_SIZE)
return 0;
/* currently edns does not change during calculations;
diff --git a/contrib/unbound/util/data/msgencode.h b/contrib/unbound/util/data/msgencode.h
index 6aff06099ee9..08fcb59b8e36 100644
--- a/contrib/unbound/util/data/msgencode.h
+++ b/contrib/unbound/util/data/msgencode.h
@@ -117,7 +117,7 @@ uint16_t calc_edns_field_size(struct edns_data* edns);
uint16_t calc_edns_option_size(struct edns_data* edns, uint16_t code);
/**
- * Calculate the size of the EDE option(s) in packet. Also calculate seperately
+ * Calculate the size of the EDE option(s) in packet. Also calculate separately
* the size of the EXTRA-TEXT field(s) in case we can trim them to fit.
* In this case include any LDNS_EDE_OTHER options in their entirety since they
* are useless without extra text.
diff --git a/contrib/unbound/util/data/msgparse.h b/contrib/unbound/util/data/msgparse.h
index 62f0d5aacd80..7de4e394f2ae 100644
--- a/contrib/unbound/util/data/msgparse.h
+++ b/contrib/unbound/util/data/msgparse.h
@@ -308,16 +308,16 @@ int parse_extract_edns_from_response_msg(struct msg_parse* msg,
/**
* Skip RRs from packet
* @param pkt: the packet. position at start must be right after the query
- * section. At end, right after EDNS data or no movement if failed.
+ * section. At end, right after EDNS data or partial movement if failed.
* @param num: Limit of the number of records we want to parse.
- * @return: 0 on success, 1 on failure.
+ * @return: 1 on success, 0 on failure.
*/
int skip_pkt_rrs(struct sldns_buffer* pkt, int num);
/**
* If EDNS data follows a query section, extract it and initialize edns struct.
* @param pkt: the packet. position at start must be right after the query
- * section. At end, right after EDNS data or no movement if failed.
+ * section. At end, right after EDNS data or partial movement if failed.
* @param edns: the edns data allocated by the caller. Does not have to be
* initialised.
* @param cfg: the configuration (with nsid value etc.)
diff --git a/contrib/unbound/util/data/msgreply.c b/contrib/unbound/util/data/msgreply.c
index e98dce133039..02e1230e96e7 100644
--- a/contrib/unbound/util/data/msgreply.c
+++ b/contrib/unbound/util/data/msgreply.c
@@ -251,7 +251,7 @@ rdata_copy(sldns_buffer* pkt, struct packed_rrset_data* data, uint8_t* to,
*rr_ttl = sldns_read_uint32(rr->ttl_data);
/* RFC 2181 Section 8. if msb of ttl is set treat as if zero. */
- if(*rr_ttl & 0x80000000U)
+ if((*rr_ttl & 0x80000000U))
*rr_ttl = 0;
if(type == LDNS_RR_TYPE_SOA && section == LDNS_SECTION_AUTHORITY) {
/* negative response. see if TTL of SOA record larger than the
@@ -984,14 +984,14 @@ log_reply_info(enum verbosity_value v, struct query_info *qinf,
if(daddr->ss_family == AF_INET6) {
struct sockaddr_in6 *d = (struct sockaddr_in6 *)daddr;
if(inet_ntop(d->sin6_family, &d->sin6_addr, da,
- sizeof(*d)) == 0)
+ sizeof(da)) == 0)
snprintf(dest_buf, sizeof(dest_buf),
"(inet_ntop_error)");
port = ntohs(d->sin6_port);
} else if(daddr->ss_family == AF_INET) {
struct sockaddr_in *d = (struct sockaddr_in *)daddr;
if(inet_ntop(d->sin_family, &d->sin_addr, da,
- sizeof(*d)) == 0)
+ sizeof(da)) == 0)
snprintf(dest_buf, sizeof(dest_buf),
"(inet_ntop_error)");
port = ntohs(d->sin_port);
@@ -1129,7 +1129,7 @@ int edns_opt_list_append_ede(struct edns_option** list, struct regional* region,
prevp = list;
while(*prevp != NULL)
prevp = &((*prevp)->next);
- verbose(VERB_ALGO, "attached EDE code: %d with message: %s", code, (txt?txt:"\"\""));
+ verbose(VERB_ALGO, "attached EDE code: %d with message: '%s'", code, (txt?txt:""));
*prevp = opt;
return 1;
}
@@ -1471,3 +1471,22 @@ struct edns_option* edns_opt_list_find(struct edns_option* list, uint16_t code)
}
return NULL;
}
+
+int local_alias_shallow_copy_qname(struct local_rrset* local_alias, uint8_t** qname,
+ size_t* qname_len)
+{
+ struct ub_packed_rrset_key* rrset = local_alias->rrset;
+ struct packed_rrset_data* d = rrset->entry.data;
+
+ /* Sanity check: our current implementation only supports
+ * a single CNAME RRset as a local alias. */
+ if(local_alias->next ||
+ rrset->rk.type != htons(LDNS_RR_TYPE_CNAME) ||
+ d->count != 1) {
+ log_err("assumption failure: unexpected local alias");
+ return 0;
+ }
+ *qname = d->rr_data[0] + 2;
+ *qname_len = d->rr_len[0] - 2;
+ return 1;
+}
diff --git a/contrib/unbound/util/data/msgreply.h b/contrib/unbound/util/data/msgreply.h
index 9c701f07d0c4..1ec4e850b8e1 100644
--- a/contrib/unbound/util/data/msgreply.h
+++ b/contrib/unbound/util/data/msgreply.h
@@ -597,7 +597,7 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len,
char text[sizeof(TXT) - 1]; \
} ede = { htons(CODE), TXT }; \
verbose(VERB_ALGO, "attached EDE code: %d with" \
- " message: %s", CODE, TXT); \
+ " message: '%s'", CODE, TXT); \
edns_opt_list_append((LIST), LDNS_EDNS_EDE, \
sizeof(uint16_t) + sizeof(TXT) - 1, \
(void *)&ede, (REGION)); \
@@ -801,4 +801,14 @@ int edns_opt_compare(struct edns_option* p, struct edns_option* q);
*/
int edns_opt_list_compare(struct edns_option* p, struct edns_option* q);
+/**
+ * Swallow copy the local_alias into the given qname and qname_len.
+ * @param local_alias: the local_alias.
+ * @param qname: the qname to copy to.
+ * @param qname_len: the qname_len to copy to.
+ * @return false on current local_alias assumptions, true otherwise.
+ */
+int local_alias_shallow_copy_qname(struct local_rrset* local_alias, uint8_t** qname,
+ size_t* qname_len);
+
#endif /* UTIL_DATA_MSGREPLY_H */