Compare commits

...

2 Commits

Author SHA1 Message Date
alessio
af207248f9 Test assumption that bindable names are fixednames 2025-02-07 12:03:06 +01:00
alessio
007e438183 Save progress 2025-02-06 22:22:13 +01:00
3 changed files with 30 additions and 80 deletions

View File

@@ -114,7 +114,6 @@ struct dns_name {
} attributes;
unsigned char *ndata;
unsigned char *offsets;
isc_buffer_t *buffer;
ISC_LINK(dns_name_t) link;
ISC_LIST(dns_rdataset_t) list;
isc_hashmap_t *hashmap;
@@ -246,13 +245,11 @@ dns_name_reset(dns_name_t *name) {
REQUIRE(DNS_NAME_VALID(name));
REQUIRE(DNS_NAME_BINDABLE(name));
// FIXME Free ndata?
name->ndata = NULL;
name->length = 0;
name->labels = 0;
name->attributes.absolute = false;
if (name->buffer != NULL) {
isc_buffer_clear(name->buffer);
}
}
/*%<
* Reinitialize 'name'.
@@ -287,7 +284,6 @@ dns_name_invalidate(dns_name_t *name) {
name->labels = 0;
name->attributes = (struct dns_name_attrs){};
name->offsets = NULL;
name->buffer = NULL;
ISC_LINK_INIT(name, link);
}
/*%<
@@ -316,9 +312,9 @@ dns_name_isvalid(const dns_name_t *name);
static inline void
dns_name_setbuffer(dns_name_t *name, isc_buffer_t *buffer) {
REQUIRE(DNS_NAME_VALID(name));
REQUIRE((buffer != NULL && name->buffer == NULL) || (buffer == NULL));
REQUIRE((buffer != NULL) || (buffer == NULL));
name->buffer = buffer;
_Static_assert(true, "FIXME make false");
}
/*%<
* Dedicate a buffer for use with 'name'.

View File

@@ -153,10 +153,12 @@ dns_name_hasbuffer(const dns_name_t *name) {
REQUIRE(DNS_NAME_VALID(name));
if (name->buffer != NULL) {
// XXX: we are assuming that bindable names come from fixed names.
if(DNS_NAME_BINDABLE(name)) {
return true;
}
_Static_assert(true, "FIXME make false or make IS_BINDABLE");
return false;
}
@@ -713,9 +715,6 @@ void
dns_name_fromregion(dns_name_t *name, const isc_region_t *r) {
unsigned char *offsets;
dns_offsets_t odata;
unsigned int len;
isc_region_t r2 = { .base = NULL, .length = 0 };
/*
* Make 'name' refer to region 'r'.
*/
@@ -727,19 +726,7 @@ dns_name_fromregion(dns_name_t *name, const isc_region_t *r) {
INIT_OFFSETS(name, offsets, odata);
name->ndata = r->base;
if (name->buffer != NULL) {
isc_buffer_clear(name->buffer);
isc_buffer_availableregion(name->buffer, &r2);
len = (r->length < r2.length) ? r->length : r2.length;
if (len > DNS_NAME_MAXWIRE) {
len = DNS_NAME_MAXWIRE;
}
name->length = len;
} else {
name->length = (r->length <= DNS_NAME_MAXWIRE)
? r->length
: DNS_NAME_MAXWIRE;
}
name->length = (r->length <= DNS_NAME_MAXWIRE) ? r->length : DNS_NAME_MAXWIRE;
if (r->length > 0) {
set_offsets(name, offsets, name);
@@ -747,19 +734,6 @@ dns_name_fromregion(dns_name_t *name, const isc_region_t *r) {
name->labels = 0;
name->attributes.absolute = false;
}
if (name->buffer != NULL) {
/*
* name->length has been updated by set_offsets to the actual
* length of the name data so we can now copy the actual name
* data and not anything after it.
*/
if (name->length > 0) {
memmove(r2.base, r->base, name->length);
}
name->ndata = r2.base;
isc_buffer_add(name->buffer, name->length);
}
}
isc_result_t
@@ -790,16 +764,10 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
REQUIRE(DNS_NAME_VALID(name));
REQUIRE(ISC_BUFFER_VALID(source));
REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) ||
(target == NULL && ISC_BUFFER_VALID(name->buffer)));
REQUIRE(target != NULL && ISC_BUFFER_VALID(target));
downcase = ((options & DNS_NAME_DOWNCASE) != 0);
if (target == NULL && name->buffer != NULL) {
target = name->buffer;
isc_buffer_clear(target);
}
REQUIRE(DNS_NAME_BINDABLE(name));
INIT_OFFSETS(name, offsets, odata);
@@ -1329,12 +1297,7 @@ dns_name_downcase(const dns_name_t *source, dns_name_t *name,
ndata = source->ndata;
} else {
REQUIRE(DNS_NAME_BINDABLE(name));
REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) ||
(target == NULL && ISC_BUFFER_VALID(name->buffer)));
if (target == NULL) {
target = name->buffer;
isc_buffer_clear(name->buffer);
}
REQUIRE(target != NULL && ISC_BUFFER_VALID(target));
ndata = (unsigned char *)target->base + target->used;
name->ndata = ndata;
}
@@ -1455,13 +1418,7 @@ dns_name_fromwire(dns_name_t *const name, isc_buffer_t *const source,
REQUIRE(DNS_NAME_VALID(name));
REQUIRE(DNS_NAME_BINDABLE(name));
REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) ||
(target == NULL && ISC_BUFFER_VALID(name->buffer)));
if (target == NULL && name->buffer != NULL) {
target = name->buffer;
isc_buffer_clear(target);
}
REQUIRE(target != NULL && ISC_BUFFER_VALID(target));
uint8_t *const name_buf = isc_buffer_used(target);
const uint32_t name_max = ISC_MIN(DNS_NAME_MAXWIRE,
@@ -1668,9 +1625,7 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix,
REQUIRE(prefix == NULL || DNS_NAME_VALID(prefix));
REQUIRE(suffix == NULL || DNS_NAME_VALID(suffix));
REQUIRE(name == NULL || DNS_NAME_VALID(name));
REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) ||
(target == NULL && name != NULL &&
ISC_BUFFER_VALID(name->buffer)));
REQUIRE(target != NULL && ISC_BUFFER_VALID(target));
if (prefix == NULL || prefix->labels == 0) {
copy_prefix = false;
}
@@ -1685,11 +1640,6 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix,
dns_name_init(&tmp_name, odata);
name = &tmp_name;
}
if (target == NULL) {
INSIST(name->buffer != NULL);
target = name->buffer;
isc_buffer_clear(name->buffer);
}
REQUIRE(DNS_NAME_BINDABLE(name));
@@ -1734,7 +1684,7 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix,
* a dedicated buffer, and we're using it, then we don't have to
* copy anything.
*/
if (copy_prefix && (prefix != name || prefix->buffer != target)) {
if (copy_prefix && prefix != name) {
memmove(ndata, prefix->ndata, prefix_length);
}
@@ -2006,11 +1956,7 @@ dns_name_fromstring(dns_name_t *target, const char *src,
isc_buffer_constinit(&buf, src, strlen(src));
isc_buffer_add(&buf, strlen(src));
if (DNS_NAME_BINDABLE(target) && target->buffer != NULL) {
name = target;
} else {
name = dns_fixedname_initname(&fn);
}
name = dns_fixedname_initname(&fn);
result = dns_name_fromtext(name, &buf, origin, options, NULL);
if (result != ISC_R_SUCCESS) {
@@ -2032,7 +1978,8 @@ dns_name_copy(const dns_name_t *source, dns_name_t *dest) {
REQUIRE(DNS_NAME_VALID(dest));
REQUIRE(DNS_NAME_BINDABLE(dest));
target = dest->buffer;
// FIXME: realloc?
// target = dest->buffer;
REQUIRE(target != NULL);
REQUIRE(target->length >= source->length);

View File

@@ -255,10 +255,13 @@ dns_qpkey_toname(const dns_qpkey_t key, size_t keylen, dns_name_t *name) {
size_t loc = 0, opos = 0;
size_t offset;
unsigned char ndata_buf[DNS_NAME_MAXWIRE] = {0};
size_t ndata_idx = 0;
REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));
REQUIRE(name->buffer != NULL);
REQUIRE(name->offsets != NULL);
// XXX: This requires BINDABLE, which in turn (I hope) implies fixedname
dns_name_reset(name);
if (keylen == 0) {
@@ -284,7 +287,6 @@ dns_qpkey_toname(const dns_qpkey_t key, size_t keylen, dns_name_t *name) {
}
UNREACHABLE();
scanned:
/*
* In the key the labels are encoded in reverse order, so
* we step backward through the label boundaries, then forward
@@ -295,8 +297,8 @@ scanned:
uint8_t len = 0, *lenp = NULL;
/* Add a length byte to the name data and set an offset */
lenp = isc_buffer_used(name->buffer);
isc_buffer_putuint8(name->buffer, 0);
lenp = &ndata_buf[ndata_idx];
ndata_buf[ndata_idx++] = 0;
name->offsets[opos++] = name->length++;
/* Convert from escaped byte ranges to ASCII */
@@ -304,10 +306,10 @@ scanned:
uint8_t bit = qpkey_bit(key, keylen, offset);
uint8_t byte = dns_qp_byte_for_bit[bit];
if (qp_common_character(byte)) {
isc_buffer_putuint8(name->buffer, byte);
ndata_buf[ndata_idx++] = byte;
} else {
byte += key[++offset] - SHIFT_BITMAP;
isc_buffer_putuint8(name->buffer, byte);
ndata_buf[ndata_idx++] = byte;
}
len++;
}
@@ -319,12 +321,17 @@ scanned:
/* Add a root label for absolute names */
if (key[0] == SHIFT_NOBYTE) {
name->attributes.absolute = true;
isc_buffer_putuint8(name->buffer, 0);
ndata_buf[ndata_idx++] = 0;
name->offsets[opos++] = name->length++;
name->labels++;
}
name->ndata = isc_buffer_base(name->buffer);
// FIXME: Realloc?
// name->ndata = isc_buffer_base(name->buffer);
// XXX: We are assuming that BINDABLE == fixedname
REQUIRE(DNS_NAME_BINDABLE(name));
memcpy(name->ndata, ndata_buf, ndata_idx);
}
/*