]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
cache: assert name is non-nul when looking up
authorPablo Neira Ayuso <pablo@netfilter.org>
Sun, 15 Jun 2025 09:33:49 +0000 (11:33 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 23 Jun 2025 16:41:05 +0000 (18:41 +0200)
{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@netfilter.org>
src/cache.c

index 3ac819cf68fb7e240f03a5f1b78278df188e63fc..d16052c608d5c4294a32b341d3db447727756112 100644 (file)
@@ -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))