Commit 6ea7ab7f authored by Jan Kadlec's avatar Jan Kadlec

rrset wire: Added a constant for DNAME count in RDATA

parent bd2a198d
......@@ -29,6 +29,7 @@
#include <stdio.h> // size_t
#define KNOT_MAX_RDATA_BLOCKS 8
#define KNOT_MAX_RDATA_DNAMES 2 // update this when defining new RR types
Please register or sign in to reply
/*!
* \brief Resource record class codes.
......
......@@ -518,15 +518,6 @@ static int parse_header(const uint8_t *pkt_wire, size_t *pos, size_t pkt_size,
return KNOT_EOK;
}
/*!
* \brief Checks whether DNAME type should be decompressed.
*/
static bool should_decompress(const int dname_type)
{
return dname_type == KNOT_RDATA_WF_COMPRESSIBLE_DNAME ||
dname_type == KNOT_RDATA_WF_DECOMPRESSIBLE_DNAME;
}
/*!
* \brief Parse and decompress RDATA.
*/
......@@ -544,7 +535,7 @@ static int decompress_rdata_dname(const uint8_t **src, size_t *src_avail,
int compr_size = knot_dname_wire_check(*src, *src + *src_avail, dname_cfg->pkt_wire);
if (compr_size <= 0) {
return KNOT_EMALF;
return compr_size;
}
int decompr_size = knot_dname_unpack(*dst, *src, *dst_avail, dname_cfg->pkt_wire);
......@@ -552,11 +543,6 @@ static int decompress_rdata_dname(const uint8_t **src, size_t *src_avail,
return decompr_size;
}
if (!should_decompress(dname_type) && (compr_size != decompr_size)) {
/* Compressed DNAME when it shouldn't be. */
return KNOT_EMALF;
}
/* Update buffers */
*dst += decompr_size;
*dst_avail -= decompr_size;
......@@ -574,26 +560,6 @@ static bool allow_zero_rdata(const knot_rrset_t *rr, const rdata_descriptor_t *d
desc->type_name == NULL; // Unknown RR type
}
/*!
* \brief Get above-maximal approximation of decompressed RDATA size.
*/
static size_t rdata_decompress_maxsize(uint16_t rdlength,
const rdata_descriptor_t *desc)
{
size_t result = rdlength;
for (int i = 0; desc->block_types[i] != KNOT_RDATA_WF_END; i++) {
int block_type = desc->block_types[i];
if (block_type == KNOT_RDATA_WF_COMPRESSIBLE_DNAME ||
block_type == KNOT_RDATA_WF_DECOMPRESSIBLE_DNAME
) {
result += KNOT_DNAME_MAXLEN;
}
}
return result;
}
/*!
* \brief Parse RDATA part of one RR from packet wireformat.
*/
......@@ -627,9 +593,10 @@ static int parse_rdata(const uint8_t *pkt_wire, size_t *pos, size_t pkt_size,
const uint8_t *src = pkt_wire + *pos;
size_t src_avail = rdlength;
size_t dst_avail = rdata_decompress_maxsize(rdlength, desc);
uint8_t rdata_buffer[dst_avail];
const size_t buffer_size = rdlength + KNOT_MAX_RDATA_DNAMES * KNOT_DNAME_MAXLEN;
uint8_t rdata_buffer[buffer_size];
uint8_t *dst = rdata_buffer;
size_t dst_avail = buffer_size;
/* Parse RDATA */
......@@ -649,7 +616,7 @@ static int parse_rdata(const uint8_t *pkt_wire, size_t *pos, size_t pkt_size,
return KNOT_EMALF;
}
size_t written = dst - rdata_buffer;
const size_t written = buffer_size - dst_avail;
if (written > MAX_RDLENGTH) {
/* DNAME compression caused RDATA overflow. */
return KNOT_EMALF;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment