From 894165c98c47a41a0e290a6a31d4634a0b6deea9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Vavrus=CC=8Ca?= Date: Thu, 11 Jan 2018 22:29:24 -0800 Subject: [PATCH] lib: fixed possible null pointers passed to nonnull arguments --- lib/dnssec/nsec3.c | 2 +- lib/generic/lru.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/dnssec/nsec3.c b/lib/dnssec/nsec3.c index 14029297b..712aeef14 100644 --- a/lib/dnssec/nsec3.c +++ b/lib/dnssec/nsec3.c @@ -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; diff --git a/lib/generic/lru.c b/lib/generic/lru.c index 7072108bb..3717d2d4d 100644 --- a/lib/generic/lru.c +++ b/lib/generic/lru.c @@ -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); -- 2.47.2