From 80e850be149b9217f7490e2de02d8e92a2ca1e0a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Vavru=C5=A1a?= <marek.vavrusa@nic.cz>
Date: Wed, 10 Jun 2015 01:36:06 +0200
Subject: [PATCH] lib/lru: args checking

---
 lib/generic/lru.h | 6 ++++++
 lib/zonecut.c     | 6 ++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/generic/lru.h b/lib/generic/lru.h
index d4125f7e8..1b38708ae 100644
--- a/lib/generic/lru.h
+++ b/lib/generic/lru.h
@@ -110,6 +110,9 @@ struct { \
 /** @internal Slot data getter */
 static inline void *lru_slot_get(struct lru_hash_base *lru, const char *key, uint32_t len, size_t offset)
 {
+	if (!lru || !key || len == 0) {
+		return NULL;
+	}
 	uint32_t id = hash(key, len) % lru->size;
 	struct lru_slot *slot = (struct lru_slot *)(lru->slots + (id * lru->stride));
 	if (lru_slot_match(slot, key, len)) {
@@ -121,6 +124,9 @@ static inline void *lru_slot_get(struct lru_hash_base *lru, const char *key, uin
 /** @internal Slot data setter */
 static inline void *lru_slot_set(struct lru_hash_base *lru, const char *key, uint32_t len, size_t offset)
 {
+	if (!lru || !key || len == 0) {
+		return NULL;
+	}
 	uint32_t id = hash(key, len) % lru->size;
 	struct lru_slot *slot = (struct lru_slot *)(lru->slots + (id * lru->stride));
 	if (!lru_slot_match(slot, key, len)) {
diff --git a/lib/zonecut.c b/lib/zonecut.c
index 143336fef..d779b482d 100644
--- a/lib/zonecut.c
+++ b/lib/zonecut.c
@@ -253,8 +253,10 @@ int kr_zonecut_find_cached(struct kr_context *ctx, struct kr_zonecut *cut, const
 	}
 
 	/* Start at QNAME parent. */
-	name = knot_wire_next_label(name, NULL);
-	while (txn && name) {
+	if (name[0] != '\0') {
+		name = knot_wire_next_label(name, NULL);
+	}
+	while (txn) {
 		if (fetch_ns(ctx, cut, name, txn, timestamp) == 0) {
 			update_cut_name(cut, name);
 			return kr_ok();
-- 
GitLab