Commit 2a6510b7 authored by Marek Vavruša's avatar Marek Vavruša

lib/zonecut: copy qname for cut lookup, as it may overlap replaced cut

parent a9fb25c7
......@@ -400,23 +400,31 @@ int kr_zonecut_find_cached(struct kr_context *ctx, struct kr_zonecut *cut, const
if (!ctx || !cut || !name) {
return kr_error(EINVAL);
}
/* Copy name as it may overlap with cut name that is to be replaced. */
knot_dname_t *qname = knot_dname_copy(name, cut->pool);
const knot_dname_t *label = qname;
if (!label) {
return kr_error(ENOMEM);
}
/* Start at QNAME parent. */
while (txn && name) {
bool has_ta = !secured || !name[0] || fetch_ta(cut, name, txn, timestamp) == 0;
if (has_ta && fetch_ns(ctx, cut, name, txn, timestamp) == 0) {
while (txn) {
const bool is_root = (label[0] == '\0');
bool has_ta = !secured || is_root || fetch_ta(cut, label, txn, timestamp) == 0;
if (has_ta && fetch_ns(ctx, cut, label, txn, timestamp) == 0) {
if (secured) {
fetch_dnskey(cut, name, txn, timestamp);
fetch_dnskey(cut, label, txn, timestamp);
}
update_cut_name(cut, name);
update_cut_name(cut, label);
mm_free(cut->pool, qname);
return kr_ok();
}
if (name[0] == '\0') {
/* Subtract label from QNAME. */
if (!is_root) {
label = knot_wire_next_label(label, NULL);
} else {
break;
}
/* Subtract label from QNAME. */
name = knot_wire_next_label(name, NULL);
}
mm_free(cut->pool, qname);
return kr_error(ENOENT);
}
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