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

cache: avoid some crashes

It's actually possible to start queries without any cache open,
e.g. add `resolve('.', kres.type.DNSKEY)` into your configuration.
If that happens, avoid the cache module dereferencing a NULL pointer.
parent 3e215037
Pipeline #41328 failed with stages
in 60 minutes and 51 seconds
......@@ -315,7 +315,8 @@ int cache_peek(kr_layer_t *ctx, knot_pkt_t *pkt)
struct kr_query *qry = req->current_query;
/* We first check various exit-conditions and then call the _real function. */
if (ctx->state & (KR_STATE_FAIL|KR_STATE_DONE) || qry->flags.NO_CACHE
if (!kr_cache_is_open(&req->ctx->cache)
|| ctx->state & (KR_STATE_FAIL|KR_STATE_DONE) || qry->flags.NO_CACHE
|| (qry->flags.CACHE_TRIED && !qry->stale_cb)
|| !check_rrtype(qry->stype, qry) /* LATER: some other behavior for some of these? */
|| qry->sclass != KNOT_CLASS_IN) {
......@@ -358,7 +359,8 @@ int cache_stash(kr_layer_t *ctx, knot_pkt_t *pkt)
/* Note: we cache even in KR_STATE_FAIL. For example,
* BOGUS answer can go to +cd cache even without +cd request. */
if (!qry || qry->flags.CACHED || !check_rrtype(knot_pkt_qtype(pkt), qry)
if (!kr_cache_is_open(cache) || !qry
|| qry->flags.CACHED || !check_rrtype(knot_pkt_qtype(pkt), qry)
|| qry->sclass != KNOT_CLASS_IN) {
return ctx->state;
}
......
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