netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft 2/5] cache: assert name is non-nul when looking up
Date: Sun, 15 Jun 2025 12:00:16 +0200	[thread overview]
Message-ID: <20250615100019.2988872-3-pablo@netfilter.org> (raw)
In-Reply-To: <20250615100019.2988872-1-pablo@netfilter.org>

{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 | 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


  parent reply	other threads:[~2025-06-15 10:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-15 10:00 [PATCH nft 0/5] assorted updates and fixes Pablo Neira Ayuso
2025-06-15 10:00 ` [PATCH nft 1/5] rule: skip fuzzy lookup if object name is not available Pablo Neira Ayuso
2025-06-15 10:00 ` Pablo Neira Ayuso [this message]
2025-06-15 10:00 ` [PATCH nft 3/5] cache: pass name to cache_add() Pablo Neira Ayuso
2025-06-15 10:00 ` [PATCH nft 4/5] parser_bison: only reset by name is supported by now Pablo Neira Ayuso
2025-06-15 10:00 ` [PATCH nft 5/5] parser_bison: allow delete command with map via handle Pablo Neira Ayuso
2025-06-23 17:08 ` [PATCH nft 0/5] assorted updates and fixes Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250615100019.2988872-3-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).