skipping over last/root label returns a pointer to a memory after domain name, this is unsafe
uint8_t namebuf[KNOT_DNAME_MAXLEN];
knot_dname_to_wire(namebuf, name, sizeof(namebuf));
knot_dname_t *ptr = namebuf;
- while (*ptr != '\0') {
+ while (ptr[0]) {
/* Remove leftmost label and replace it with '\1*'. */
ptr = (uint8_t *) knot_wire_next_label(ptr, NULL);
*(--ptr) = '*';
goto fail;
}
+ /* Root label has no encloser */
+ if (!name[0]) {
+ ret = kr_error(ENOENT);
+ goto fail;
+ }
+
const knot_dname_t *encloser = knot_wire_next_label(name, NULL);
*skipped = 1;
- do {
+ while(encloser) {
ret = hash_name(&name_hash, ¶ms, encloser);
if (ret != 0) {
goto fail;
dnssec_binary_free(&name_hash);
+ if (!encloser[0])
+ break;
encloser = knot_wire_next_label(encloser, NULL);
++(*skipped);
- } while (encloser && (encloser[0] != '\0'));
+ }
ret = kr_ok();
--skipped;
next_closer = sname;
for (unsigned j = 0; j < skipped; ++j) {
+ assert(next_closer[0]);
next_closer = knot_wire_next_label(next_closer, NULL);
}
for (unsigned j = 0; j < sec->count; ++j) {
}
if ((flags & FLG_CLOSEST_PROVABLE_ENCLOSER) && (flags & FLG_NAME_COVERED) && next_closer) {
- if (encloser_name) {
+ if (encloser_name && next_closer[0]) {
*encloser_name = knot_wire_next_label(next_closer, NULL);
}
if (matching_ecloser_nsec3) {
/* Compute the next closer name. */
for (int i = 0; i < trim_to_next; ++i) {
+ assert(sname[0]);
sname = knot_wire_next_label(sname, NULL);
}
if (trim_labels > 0) {
/**/
for (int i = 0; i < trim_labels; ++i) {
+ assert(owner[0]);
owner = (uint8_t *) knot_wire_next_label(owner, NULL);
}
*(--owner) = '*';
static void randomized_qname_case(knot_dname_t *qname, uint32_t secret)
{
unsigned k = 0;
- while (*qname != '\0') {
+ while (qname[0]) {
for (unsigned i = *qname; i--;) {
int chr = qname[i + 1];
if (isalpha(chr)) {
const knot_dname_t *target = qry->sname;
const knot_dname_t *cut_name = qry->zone_cut.name;
+ if (!target || !cut_name)
+ return;
+
struct kr_cache_entry *entry = NULL;
/* @note: The non-terminal must be direct child of zone cut (e.g. label distance <= 2),
* otherwise this would risk leaking information to parent if the NODATA TTD > zone cut TTD. */
- size_t labels = knot_dname_labels(target, NULL) - knot_dname_labels(cut_name, NULL);
- while (labels > 2) {
+ int labels = knot_dname_labels(target, NULL) - knot_dname_labels(cut_name, NULL);
+ while (target[0] && labels > 2) {
target = knot_wire_next_label(target, NULL);
--labels;
}
- for (size_t i = 0; i < labels; ++i) {
+ for (int i = 0; i < labels; ++i) {
int ret = kr_cache_peek(txn, KR_CACHE_PKT, target, KNOT_RRTYPE_NS, &entry, ×tamp);
if (ret == 0) { /* Either NXDOMAIN or NODATA, start here. */
/* @todo We could stop resolution here for NXDOMAIN, but we can't because of broken CDNs */
kr_make_query(qry, pkt);
return;
}
+ assert(target[0]);
target = knot_wire_next_label(target, NULL);
}
}