if (!eh->is_packet) { /* Positive RRset + its RRsig set (may be empty). */
int sets = 2;
while (sets-- > 0) {
- if (d + 1 > data_bound) return kr_error(EILSEQ);
- uint8_t rr_count;
- memcpy(&rr_count, d++, sizeof(rr_count));
+ if (d + 2 > data_bound) return kr_error(EILSEQ);
+ uint16_t rr_count;
+ memcpy(&rr_count, d, sizeof(rr_count));
+ d += sizeof(rr_count);
for (int i = 0; i < rr_count; ++i) {
if (d + 2 > data_bound) return kr_error(EILSEQ);
uint16_t len;
{
//const void *data0 = data;
assert(data);
- if (rds && rds->rr_count > 255) {
- return kr_error(ENOSPC);
+ if (!data) {
+ return kr_error(EINVAL);
}
- uint8_t rr_count = rds ? rds->rr_count : 0;
- memcpy(data++, &rr_count, sizeof(rr_count));
+ uint16_t rr_count = rds ? rds->rr_count : 0;
+ memcpy(data, &rr_count, sizeof(rr_count));
+ data += sizeof(rr_count);
knot_rdata_t *rd = rds ? rds->data : NULL;
for (int i = 0; i < rr_count; ++i, rd = kr_rdataset_next(rd)) {
assert(pool); /* not required, but that's our current usage; guard leaks */
const void *d = data; /* iterates over the cache data */
{
- uint8_t rr_count;
- memcpy(&rr_count, d++, sizeof(rr_count));
+ uint16_t rr_count;
+ memcpy(&rr_count, d, sizeof(rr_count));
+ d += sizeof(rr_count);
rds->rr_count = rr_count;
if (!rr_count) { /* avoid mm_alloc(pool, 0); etc. */
return d - data;
return kr_error(ENOMEM);
}
/* Construct the output, one "RR" at a time. */
- d = data + 1/*sizeof(rr_count)*/;
+ d = data + KR_CACHE_RR_COUNT_SIZE;
knot_rdata_t *d_out = rds->data; /* iterates over the output being materialized */
for (int i = 0; i < rds->rr_count; ++i) {
uint16_t len;
/* RRset (de)materialization; implementation in ./entry_rr.c */
+/** Size of the RR count field */
+#define KR_CACHE_RR_COUNT_SIZE sizeof(uint16_t)
+
/** Compute size of dematerialized rdataset. NULL is accepted as empty set. */
static inline int rdataset_dematerialize_size(const knot_rdataset_t *rds)
{
- return 1/*sizeof(rr_count)*/ + (rds
+ return KR_CACHE_RR_COUNT_SIZE + (rds
? knot_rdataset_size(rds) - 4 * rds->rr_count /*TTLs*/
: 0);
}
}
/* We know it starts before sname, so let's check the other end.
* 1. construct the key for the next name - kwz_hi. */
- const knot_dname_t *next = eh->data + 3; /* it's *full* name ATM */
+ const knot_dname_t *next = eh->data + 2 * KR_CACHE_RR_COUNT_SIZE; /* it's *full* name ATM */
if (!eh->data[0]) {
assert(false);
return "ERROR";