From: Marek VavrusÌŒa Date: Fri, 12 Jan 2018 06:07:30 +0000 (-0800) Subject: lib: fixed minor linter issues in lib X-Git-Tag: v2.0.0~36^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4fa44d1240c67d53f59495d84927eee514f3a21c;p=thirdparty%2Fknot-resolver.git lib: fixed minor linter issues in lib --- diff --git a/lib/dnssec.c b/lib/dnssec.c index 98a89d63a..1d290733d 100644 --- a/lib/dnssec.c +++ b/lib/dnssec.c @@ -333,7 +333,7 @@ int kr_dnskeys_trusted(kr_rrset_validation_ctx_t *vctx, const knot_rrset_t *ta) continue; } - struct dseckey *key; + struct dseckey *key = NULL; if (kr_dnssec_key_from_rdata(&key, keys->owner, key_data, knot_rdata_rdlen(krr)) != 0) { continue; } diff --git a/lib/dnssec/nsec.c b/lib/dnssec/nsec.c index ea64678ea..3335b3e8f 100644 --- a/lib/dnssec/nsec.c +++ b/lib/dnssec/nsec.c @@ -141,6 +141,9 @@ static int name_error_response_check_rr(int *flags, const knot_rrset_t *nsec, while (ptr[0]) { /* Remove leftmost label and replace it with '\1*'. */ ptr = (uint8_t *) knot_wire_next_label(ptr, NULL); + if (!ptr) { + return kr_error(EINVAL); + } *(--ptr) = '*'; *(--ptr) = 1; /* True if this wildcard provably doesn't exist. */ diff --git a/lib/dnssec/signature.c b/lib/dnssec/signature.c index 7c5ad16f9..521412bc4 100644 --- a/lib/dnssec/signature.c +++ b/lib/dnssec/signature.c @@ -210,6 +210,7 @@ static int sign_ctx_add_records(dnssec_sign_ctx_t *ctx, const knot_rrset_t *cove for (int j = 0; j < trim_labels; ++j) { assert(beginp[0]); beginp = (uint8_t *) knot_wire_next_label(beginp, NULL); + assert(beginp != NULL); } *(--beginp) = '*'; *(--beginp) = 1; diff --git a/lib/generic/map.c b/lib/generic/map.c index 81a283dc5..da47b817c 100644 --- a/lib/generic/map.c +++ b/lib/generic/map.c @@ -326,10 +326,14 @@ EXPORT void map_clear(map_t *map) EXPORT int map_walk_prefixed(map_t *map, const char *prefix, int (*callback)(const char *, void *, void *), void *baton) { + if (!map) { + return 0; + } + const uint8_t *ubytes = (void *)prefix; const size_t ulen = strlen(prefix); uint8_t *p = map->root; - uint8_t *top = (uint8_t *)p; + uint8_t *top = p; cb_data_t *data = NULL; if (p == NULL) { diff --git a/lib/nsrep.c b/lib/nsrep.c index e4452b57d..a2691007e 100644 --- a/lib/nsrep.c +++ b/lib/nsrep.c @@ -400,6 +400,8 @@ int kr_nsrep_sort(struct kr_nsrep *ns, kr_nsrep_lru_t *cache) } } + /* At least two addresses must be in the address list */ + assert(count > 0); ns->score = scores[0]; ns->reputation = 0; return kr_ok(); diff --git a/lib/resolve.c b/lib/resolve.c index 1589a2583..7b9fb0e0a 100644 --- a/lib/resolve.c +++ b/lib/resolve.c @@ -1296,7 +1296,7 @@ static int zone_cut_check(struct kr_request *request, struct kr_query *qry, knot } while (state == KR_STATE_CONSUME); /* Update minimized QNAME if zone cut changed */ - if (qry->zone_cut.name[0] != '\0' && !(qry->flags.NO_MINIMIZE)) { + if (qry->zone_cut.name && qry->zone_cut.name[0] != '\0' && !(qry->flags.NO_MINIMIZE)) { if (kr_make_query(qry, packet) != 0) { return KR_STATE_FAIL; } diff --git a/lib/utils.c b/lib/utils.c index 4cdff4297..ac14767ce 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -108,6 +108,10 @@ void kr_log_verbose(const char *fmt, ...) char* kr_strcatdup(unsigned n, ...) { + if (n < 1) { + return NULL; + } + /* Calculate total length */ size_t total_len = 0; va_list vl; @@ -402,7 +406,7 @@ int kr_straddr_subnet(void *dst, const char *addr) if (subnet) { *subnet = '\0'; subnet += 1; - bit_len = atoi(subnet); + bit_len = strtol(subnet, NULL, 10); /* Check client subnet length */ const int max_len = (family == AF_INET6) ? 128 : 32; if (bit_len < 0 || bit_len > max_len) {