Skip to content
Snippets Groups Projects
Commit 2cd9a2f5 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

Merge branch 'fix_zero_label_compression' into 'master'

libknot: don't compress zero label dname

See merge request !414
parents e3baf8d3 2b89cb6f
No related branches found
No related tags found
No related merge requests found
......@@ -94,9 +94,6 @@ knot_dname_t *knot_dname_copy_part(const knot_dname_t *name, unsigned len,
* \param maxlen Maximum wire length.
*
* \return number of bytes written
*
* \todo For most use cases this could be replaced by counting the length
* and simple memcpy.
*/
int knot_dname_to_wire(uint8_t *dst, const knot_dname_t *src, size_t maxlen);
......
......@@ -55,18 +55,18 @@ _public_
int knot_compr_put_dname(const knot_dname_t *dname, uint8_t *dst, uint16_t max,
knot_compr_t *compr)
{
/* Write uncompressible names directly. */
if (dname == NULL || dst == NULL) {
return KNOT_EINVAL;
}
/* Write uncompressible names directly (zero label dname). */
if (compr == NULL || *dname == '\0') {
return knot_dname_to_wire(dst, dname, max);
}
/* Get number of labels (should not be a zero label dname). */
int name_labels = knot_dname_labels(dname, NULL);
if (name_labels < 0) {
return name_labels;
}
assert(name_labels > 0);
/* Suffix must not be longer than whole name. */
const knot_dname_t *suffix = compr->wire + compr->suffix.pos;
......
......@@ -284,7 +284,12 @@ static int write_owner(const knot_rrset_t *rrset, uint8_t **dst, size_t *dst_ava
assert(dst && *dst);
assert(dst_avail);
uint16_t owner_pointer = compr_get_ptr(compr, KNOT_COMPR_HINT_OWNER);
/* Check for zero label owner (don't compress). */
uint16_t owner_pointer = 0;
if (*rrset->owner != '\0') {
owner_pointer = compr_get_ptr(compr, KNOT_COMPR_HINT_OWNER);
}
/* Check size */
......@@ -393,7 +398,6 @@ static int compress_rdata_dname(const uint8_t **src, size_t *src_avail,
int written = knot_compr_put_dname(dname, *dst, dname_max(*dst_avail),
put_compr);
if (written < 0) {
assert(written == KNOT_ESPACE);
return written;
}
......@@ -514,9 +518,7 @@ int knot_rrset_to_wire(const knot_rrset_t *rrset, uint8_t *wire, uint16_t max_si
}
}
size_t written = write - wire;
return written;
return write - wire;
}
/*- RRSet from wire ---------------------------------------------------------*/
......@@ -644,7 +646,7 @@ static int parse_rdata(const uint8_t *pkt_wire, size_t *pos, size_t pkt_size,
if (buffer_size < 0) {
return buffer_size;
}
if (buffer_size > MAX_RDLENGTH) {
/* DNAME compression caused RDATA overflow. */
return KNOT_EMALF;
......@@ -680,7 +682,7 @@ static int parse_rdata(const uint8_t *pkt_wire, size_t *pos, size_t pkt_size,
knot_rdataset_unreserve(rrs, mm);
return ret;
}
/* Update position pointer. */
*pos += rdlength;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment