Commit 802f6b44 authored by Vladimír Čunát's avatar Vladimír Čunát

iterate, nsrep: more resiliency to possible errors

parent 0ad073bf
......@@ -158,11 +158,17 @@ static int update_nsaddr(const knot_rrset_t *rr, struct kr_query *query, int *gl
{
if (rr->type == KNOT_RRTYPE_A || rr->type == KNOT_RRTYPE_AAAA) {
const knot_rdata_t *rdata = rr->rrs.rdata;
const int a_len = rr->type == KNOT_RRTYPE_A
? sizeof(struct in_addr) : sizeof(struct in6_addr);
if (a_len != rdata->len) {
QVERBOSE_MSG(query, "<= ignoring invalid glue, length %d != %d\n",
(int)rdata->len, a_len);
return KR_STATE_FAIL;
}
char name_str[KR_DNAME_STR_MAXLEN];
char addr_str[INET6_ADDRSTRLEN];
WITH_VERBOSE(query) {
const int af = (rdata->len == sizeof(struct in_addr)) ?
AF_INET : AF_INET6;
const int af = (rr->type == KNOT_RRTYPE_A) ? AF_INET : AF_INET6;
knot_dname_to_str(name_str, rr->owner, sizeof(name_str));
name_str[sizeof(name_str) - 1] = 0;
inet_ntop(af, rdata->data, addr_str, sizeof(addr_str));
......
......@@ -102,8 +102,11 @@ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx,
if (len == sizeof(struct in6_addr)) {
is_valid = !(opts.NO_IPV6);
favour = FAVOUR_IPV6;
} else {
} else if (len == sizeof(struct in_addr)) {
is_valid = !(opts.NO_IPV4);
} else {
assert(!EINVAL);
is_valid = false;
}
if (!is_valid) {
......
......@@ -167,8 +167,16 @@ int kr_zonecut_copy_trust(struct kr_zonecut *dst, const struct kr_zonecut *src)
int kr_zonecut_add(struct kr_zonecut *cut, const knot_dname_t *ns, const knot_rdata_t *rdata)
{
if (!cut || !ns || !cut->nsset) {
assert(!EINVAL);
return kr_error(EINVAL);
}
/* Disabled; add_reverse_pair() misuses this for domain name in rdata. */
if (false && rdata && rdata->len != sizeof(struct in_addr)
&& rdata->len != sizeof(struct in6_addr)) {
assert(!EINVAL);
return kr_error(EINVAL);
}
/* Get a pack_t for the ns. */
pack_t **pack = (pack_t **)trie_get_ins(cut->nsset, (const char *)ns, knot_dname_size(ns));
if (!pack) return kr_error(ENOMEM);
......
......@@ -28,7 +28,9 @@ static void test_zonecut_params(void **state)
kr_zonecut_deinit(NULL);
kr_zonecut_set(NULL, NULL);
kr_zonecut_set(&cut, NULL);
/* TODO triggerring inner assert:
assert_int_not_equal(kr_zonecut_add(NULL, NULL, NULL), 0);
*/
assert_null((void *)kr_zonecut_find(NULL, NULL));
assert_null((void *)kr_zonecut_find(&cut, NULL));
assert_int_not_equal(kr_zonecut_set_sbelt(NULL, NULL), 0);
......
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