[PATCH nft 2/5] cache: assert name is non-nul when looking up

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



{table,chain,set,obj,flowtable}_cache_find() should not be called when
handles are used

Fixes: 5ec5c706d993 ("cache: add hashtable cache for table")
Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>
---
 src/cache.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/cache.c b/src/cache.c
index 3ac819cf68fb..d16052c608d5 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -551,8 +551,7 @@ struct table *table_cache_find(const struct cache *cache,
 	struct table *table;
 	uint32_t hash;
 
-	if (!name)
-		return NULL;
+	assert(name);
 
 	hash = djb_hash(name) % NFT_CACHE_HSIZE;
 	list_for_each_entry(table, &cache->ht[hash], cache.hlist) {
@@ -672,6 +671,8 @@ struct chain *chain_cache_find(const struct table *table, const char *name)
 	struct chain *chain;
 	uint32_t hash;
 
+	assert(name);
+
 	hash = djb_hash(name) % NFT_CACHE_HSIZE;
 	list_for_each_entry(chain, &table->chain_cache.ht[hash], cache.hlist) {
 		if (!strcmp(chain->handle.chain.name, name))
@@ -840,6 +841,8 @@ struct set *set_cache_find(const struct table *table, const char *name)
 	struct set *set;
 	uint32_t hash;
 
+	assert(name);
+
 	hash = djb_hash(name) % NFT_CACHE_HSIZE;
 	list_for_each_entry(set, &table->set_cache.ht[hash], cache.hlist) {
 		if (!strcmp(set->handle.set.name, name))
@@ -954,6 +957,8 @@ struct obj *obj_cache_find(const struct table *table, const char *name,
 	struct obj *obj;
 	uint32_t hash;
 
+	assert(name);
+
 	hash = djb_hash(name) % NFT_CACHE_HSIZE;
 	list_for_each_entry(obj, &table->obj_cache.ht[hash], cache.hlist) {
 		if (!strcmp(obj->handle.obj.name, name) &&
@@ -1058,6 +1063,8 @@ struct flowtable *ft_cache_find(const struct table *table, const char *name)
 	struct flowtable *ft;
 	uint32_t hash;
 
+	assert(name);
+
 	hash = djb_hash(name) % NFT_CACHE_HSIZE;
 	list_for_each_entry(ft, &table->ft_cache.ht[hash], cache.hlist) {
 		if (!strcmp(ft->handle.flowtable.name, name))
-- 
2.30.2





[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux