* SPDX-License-Identifier: GPL-3.0-or-later
*/
-#include <assert.h>
#include <ccan/json/json.h>
#include <libknot/db/db_lmdb.h>
#include <libknot/error.h>
const uint8_t *cc, uint16_t cc_len,
const struct kr_cookie_settings *clnt_sett)
{
- assert(cc && cc_len > 0 && clnt_sett);
+ if (!kr_assume(cc && cc_len > 0 && clnt_sett))
+ return -2;
if (!srvr_sa) {
return -2;
}
- assert(clnt_sett->current.secr);
+ if (!kr_assume(clnt_sett->current.secr))
+ return -2;
/* The address must correspond with the client cookie. */
struct knot_cc_input input = {
static const uint8_t *get_cookie_opt(kr_cookie_lru_t *cache,
const struct sockaddr *sa)
{
- assert(cache && sa);
+ if (!kr_assume(cache && sa))
+ return NULL;
const uint8_t *cached_cookie_opt = kr_cookie_lru_get(cache, sa);
if (!cached_cookie_opt) {
static bool is_cookie_cached(kr_cookie_lru_t *cache, const struct sockaddr *sa,
const uint8_t *cookie_opt)
{
- assert(cache && sa && cookie_opt);
+ if (!kr_assume(cache && sa && cookie_opt))
+ return false;
const uint8_t *cached_opt = get_cookie_opt(cache, sa);
if (!cached_opt) {
uint8_t *pkt_cookie_opt,
kr_cookie_lru_t *cache)
{
- assert(clnt_sett && req && pkt_cookie_opt && cache);
+ if (!kr_assume(clnt_sett && req && pkt_cookie_opt && cache))
+ return false;
const uint8_t *pkt_cookie_data = knot_edns_opt_get_data(pkt_cookie_opt);
uint16_t pkt_cookie_len = knot_edns_opt_get_length(pkt_cookie_opt);
"got malformed DNS cookie or server cookie missing");
return false;
}
- assert(pkt_cc_len == KNOT_OPT_COOKIE_CLNT);
+ if (!kr_assume(pkt_cc_len == KNOT_OPT_COOKIE_CLNT))
+ return false;
/* Check server address against received client cookie. */
const struct sockaddr *srvr_sockaddr = passed_server_sockaddr(req);
VERBOSE_MSG(NULL, "%s\n", "could not match received cookie");
return false;
}
- assert(srvr_sockaddr);
+ if (!kr_assume(srvr_sockaddr))
+ return false;
/* Don't cache received cookies that don't match the current secret. */
if ((ret == 1) &&
static int invalid_sc_status(int state, bool sc_present, bool ignore_badcookie,
const struct kr_request *req, knot_pkt_t *answer)
{
- assert(req && answer);
+ if (!kr_assume(req && answer))
+ return KR_STATE_FAIL;
const knot_pkt_t *pkt = req->qsource.packet;