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

fixup! treewide: safer structure literals and initialization

parent d0841a23
......@@ -429,7 +429,8 @@ static int cache_peek_real(kr_layer_t *ctx, knot_pkt_t *pkt)
/* collecting multiple NSEC* + RRSIG records, in preparation for the answer
* + track the progress
*/
struct answer ans = {};
struct answer ans;
memset(&ans, 0, sizeof(ans));
ans.mm = &pkt->mm;
/** Start of NSEC* covering the sname;
......@@ -839,7 +840,8 @@ static int answer_simple_hit(kr_layer_t *ctx, knot_pkt_t *pkt, uint16_t type,
CHECK_RET(ret);
/* Materialize the sets for the answer in (pseudo-)packet. */
struct answer ans = {};
struct answer ans;
memset(&ans, 0, sizeof(ans));
ret = entry2answer(&ans, AR_ANSWER, eh, eh_bound,
qry->sname, type, new_ttl);
CHECK_RET(ret);
......
......@@ -161,7 +161,7 @@ static const char * find_leq_NSEC1(struct kr_cache *cache, const struct kr_query
return "range search ERROR";
}
knot_db_val_t key_nsec = key;
knot_db_val_t val = { };
knot_db_val_t val = { NULL, 0 };
int ret = cache_op(cache, read_leq, &key_nsec, &val);
if (ret < 0) {
if (ret == kr_error(ENOENT)) {
......@@ -279,7 +279,7 @@ int nsec1_encloser(struct key *k, struct answer *ans,
/* Find a previous-or-equal name+NSEC in cache covering the QNAME,
* checking TTL etc. */
knot_db_val_t key = key_NSEC1(k, qry->sname, false);
knot_db_val_t val = {};
knot_db_val_t val = { NULL, 0 };
bool exact_match;
uint32_t new_ttl;
const char *err = find_leq_NSEC1(cache, qry, key, k, &val,
......@@ -408,8 +408,8 @@ int nsec1_src_synth(struct key *k, struct answer *ans, const knot_dname_t *clenc
nsec_rr = ans->rrsets[AR_NSEC].set.rr;
} else {
/* Try to find the NSEC for SS. */
knot_db_val_t val = {};
knot_db_val_t wild_low_kwz = {};
knot_db_val_t val = { NULL, 0 };
knot_db_val_t wild_low_kwz = { NULL, 0 };
uint32_t new_ttl;
const char *err = find_leq_NSEC1(cache, qry, key, k, &val,
&exact_match, &wild_low_kwz, NULL, &new_ttl);
......
......@@ -556,7 +556,7 @@ static int cdb_remove(knot_db_t *db, knot_db_val_t *key, int maxcount)
for (int i = 0; ret == kr_ok() && i < maxcount; ++i) {
MDB_val _key = val_knot2mdb(key[i]);
MDB_val val = { };
MDB_val val = { 0, NULL };
ret = lmdb_error(mdb_del(txn, env->dbi, &_key, &val));
}
......@@ -585,7 +585,7 @@ static int cdb_match(knot_db_t *db, knot_db_val_t *key, knot_db_val_t *val, int
}
MDB_val cur_key = val_knot2mdb(*key);
MDB_val cur_val = { };
MDB_val cur_val = { 0, NULL };
ret = mdb_cursor_get(cur, &cur_key, &cur_val, MDB_SET_RANGE);
if (ret != MDB_SUCCESS) {
mdb_cursor_close(cur);
......@@ -675,7 +675,7 @@ static int cdb_read_leq(knot_db_t *env, knot_db_val_t *key, knot_db_val_t *val)
if (ret) return ret;
MDB_val key2_m = val_knot2mdb(*key);
MDB_val val2_m = { };
MDB_val val2_m = { 0, NULL };
ret = mdb_cursor_get(curs, &key2_m, &val2_m, MDB_SET_RANGE);
if (ret) return lmdb_error(ret);
/* test for equality //:unlikely */
......
......@@ -53,9 +53,10 @@ static int nsec3_parameters(dnssec_nsec3_params_t *params, const knot_rrset_t *n
/* Every NSEC3 RR contains data from NSEC3PARAMS. */
const size_t SALT_OFFSET = 5; /* First 5 octets contain { Alg, Flags, Iterations, Salt length } */
dnssec_binary_t rdata = {0, };
rdata.size = SALT_OFFSET + (size_t) knot_nsec3_salt_length(&nsec3->rrs, 0);
rdata.data = knot_rdata_data(rr);
dnssec_binary_t rdata = {
.size = SALT_OFFSET + (size_t) knot_nsec3_salt_length(&nsec3->rrs, 0),
.data = knot_rdata_data(rr),
};
if (rdata.size > knot_rdata_rdlen(rr))
return kr_error(EMSGSIZE);
......@@ -81,9 +82,10 @@ static int hash_name(dnssec_binary_t *hash, const dnssec_nsec3_params_t *params,
if (!name)
return kr_error(EINVAL);
dnssec_binary_t dname = {0, };
dname.size = knot_dname_size(name);
dname.data = (uint8_t *) name;
dnssec_binary_t dname = {
.size = knot_dname_size(name),
.data = (uint8_t *) name,
};
int ret = dnssec_nsec3_hash(&dname, params, hash);
if (ret != DNSSEC_EOK) {
......@@ -128,11 +130,10 @@ static int closest_encloser_match(int *flags, const knot_rrset_t *nsec3,
{
assert(flags && nsec3 && name && skipped);
dnssec_binary_t owner_hash = {0, };
uint8_t hash_data[MAX_HASH_BYTES] = {0, };
owner_hash.data = hash_data;
dnssec_nsec3_params_t params = {0, };
dnssec_binary_t name_hash = {0, };
dnssec_binary_t owner_hash = { 0, hash_data };
dnssec_nsec3_params_t params = { 0, };
dnssec_binary_t name_hash = { 0, };
int ret = read_owner_hash(&owner_hash, MAX_HASH_BYTES, nsec3);
if (ret != 0) {
......@@ -197,11 +198,10 @@ static int covers_name(int *flags, const knot_rrset_t *nsec3, const knot_dname_t
{
assert(flags && nsec3 && name);
dnssec_binary_t owner_hash = {0, };
uint8_t hash_data[MAX_HASH_BYTES] = {0, };
owner_hash.data = hash_data;
dnssec_nsec3_params_t params = {0, };
dnssec_binary_t name_hash = {0, };
uint8_t hash_data[MAX_HASH_BYTES] = { 0, };
dnssec_binary_t owner_hash = { 0, hash_data };
dnssec_nsec3_params_t params = { 0, };
dnssec_binary_t name_hash = { 0, };
int ret = read_owner_hash(&owner_hash, MAX_HASH_BYTES, nsec3);
if (ret != 0) {
......@@ -305,11 +305,10 @@ static int matches_name(const knot_rrset_t *nsec3, const knot_dname_t *name)
{
assert(nsec3 && name);
dnssec_binary_t owner_hash = {0, };
uint8_t hash_data[MAX_HASH_BYTES] = {0, };
owner_hash.data = hash_data;
dnssec_nsec3_params_t params = {0, };
dnssec_binary_t name_hash = {0, };
uint8_t hash_data[MAX_HASH_BYTES] = { 0, };
dnssec_binary_t owner_hash = { 0, hash_data };
dnssec_nsec3_params_t params = { 0, };
dnssec_binary_t name_hash = { 0, };
int ret = read_owner_hash(&owner_hash, MAX_HASH_BYTES, nsec3);
if (ret != 0) {
......
......@@ -37,7 +37,7 @@
static int authenticate_ds(const dnssec_key_t *key, dnssec_binary_t *ds_rdata, uint8_t digest_type)
{
/* Compute DS RDATA from the DNSKEY. */
dnssec_binary_t computed_ds = {0, };
dnssec_binary_t computed_ds = { 0, };
int ret = dnssec_key_create_ds(key, digest_type, &computed_ds);
if (ret != DNSSEC_EOK) {
goto fail;
......@@ -139,9 +139,10 @@ static int sign_ctx_add_self(dnssec_sign_ctx_t *ctx, const uint8_t *rdata)
// static header
dnssec_binary_t header = { 0 };
header.data = (uint8_t *)rdata;
header.size = RRSIG_RDATA_SIGNER_OFFSET;
dnssec_binary_t header = {
.data = (uint8_t *)rdata,
.size = RRSIG_RDATA_SIGNER_OFFSET,
};
result = dnssec_sign_add(ctx, &header);
if (result != DNSSEC_EOK) {
......@@ -272,7 +273,7 @@ int kr_check_signature(const knot_rrset_t *rrsigs, size_t pos,
int ret = 0;
dnssec_sign_ctx_t *sign_ctx = NULL;
dnssec_binary_t signature = {0, };
dnssec_binary_t signature = { 0, NULL };
knot_rrsig_signature(&rrsigs->rrs, pos, &signature.data, &signature.size);
if (!signature.data || !signature.size) {
......
......@@ -227,7 +227,7 @@ static int ns_fetch_cut(struct kr_query *qry, const knot_dname_t *requested_name
qry->flags.DNSSEC_WANT = false;
}
struct kr_zonecut cut_found = {0};
struct kr_zonecut cut_found;
kr_zonecut_init(&cut_found, requested_name, req->rplan.pool);
/* Cut that has been found can differs from cut that has been requested.
* So if not already insecured,
......
......@@ -274,7 +274,7 @@ static void fetch_addr(struct kr_zonecut *cut, struct kr_cache *cache,
const struct kr_query *qry)
// LATER(optim.): excessive data copying
{
struct kr_cache_p peek = {};
struct kr_cache_p peek;
if (kr_cache_peek_exact(cache, ns, rrtype, &peek) != 0) {
return;
}
......@@ -300,7 +300,7 @@ static int fetch_ns(struct kr_context *ctx, struct kr_zonecut *cut,
const knot_dname_t *name, const struct kr_query *qry,
uint8_t * restrict rank)
{
struct kr_cache_p peek = {};
struct kr_cache_p peek;
int ret = kr_cache_peek_exact(&ctx->cache, name, KNOT_RRTYPE_NS, &peek);
if (ret != 0) {
return ret;
......@@ -314,7 +314,7 @@ static int fetch_ns(struct kr_context *ctx, struct kr_zonecut *cut,
* records that weren't validated.
*/
/* Materialize the rdataset temporarily, for simplicity. */
knot_rdataset_t ns_rds = {};
knot_rdataset_t ns_rds = { 0, NULL };
ret = kr_cache_materialize(&ns_rds, &peek, new_ttl, cut->pool);
if (ret < 0) {
return ret;
......@@ -352,7 +352,7 @@ static int fetch_secure_rrset(knot_rrset_t **rr, struct kr_cache *cache,
return kr_error(ENOENT);
}
/* peek, check rank and TTL */
struct kr_cache_p peek = {};
struct kr_cache_p peek;
int ret = kr_cache_peek_exact(cache, owner, type, &peek);
if (ret != 0) {
return ret;
......
......@@ -375,7 +375,8 @@ int check_request(kr_layer_t *ctx)
return ctx->state; /* Don't do anything without cookies. */
}
struct knot_dns_cookies cookies = { 0, };
struct knot_dns_cookies cookies;
memset(&cookies, 0, sizeof(cookies));
int ret = kr_parse_cookie_opt(req_cookie_opt, &cookies);
if (ret != kr_ok()) {
/* FORMERR -- malformed cookies. */
......
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