]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib: fixed possible null pointers passed to nonnull arguments
authorMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 12 Jan 2018 06:29:24 +0000 (22:29 -0800)
committerMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 12 Jan 2018 06:29:24 +0000 (22:29 -0800)
lib/dnssec/nsec3.c
lib/generic/lru.c

index 14029297b35b5a573be7e58113fc4e1eac63d257..712aeef14158b938c99fd3dfc13be3556c14b383 100644 (file)
@@ -222,7 +222,7 @@ static int covers_name(int *flags, const knot_rrset_t *nsec3, const knot_dname_t
        uint8_t *next_hash = NULL;
        knot_nsec3_next_hashed(&nsec3->rrs, 0, &next_hash, &next_size);
 
-       if ((owner_hash.size == next_size) && (name_hash.size == next_size)) {
+       if ((next_size > 0) && (owner_hash.size == next_size) && (name_hash.size == next_size)) {
                /* All hash lengths must be same. */
                const uint8_t *ownrd = owner_hash.data;
                const uint8_t *nextd = next_hash;
index 7072108bbe07bf91277c95e25227dc99d8d834ce..3717d2d4d6ce62c0455aae74a7bb56f907b33999 100644 (file)
@@ -152,7 +152,7 @@ KR_EXPORT void * lru_get_impl(struct lru *lru, const char *key, uint key_len,
                if (g->hashes[i] == khash_top) {
                        it = g->items[i];
                        if (likely(it && it->key_len == key_len
-                                       && memcmp(it->data, key, key_len) == 0))
+                                       && (key_len == 0 || memcmp(it->data, key, key_len) == 0)))
                                goto found; // to reduce huge nesting depth
                }
        }
@@ -200,7 +200,9 @@ insert: // insert into position i (incl. key)
        }
        it->key_len = key_len;
        it->val_len = val_len;
-       memcpy(it->data, key, key_len);
+       if (key_len > 0) {
+               memcpy(it->data, key, key_len);
+       }
        memset(item_val(it), 0, val_len); // clear the value
 found: // key and hash OK on g->items[i]; now update stamps
        assert(i < LRU_ASSOC);