All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Phil Sutter <phil@nwl.cc>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [nft PATCH] misspell: Avoid segfault with anonymous chains
Date: Fri, 4 Mar 2022 12:11:53 +0100	[thread overview]
Message-ID: <YiHz+bNsLvFjkPit@salvia> (raw)
In-Reply-To: <20220304103711.23355-1-phil@nwl.cc>

[-- Attachment #1: Type: text/plain, Size: 1172 bytes --]

Hi Phil,

On Fri, Mar 04, 2022 at 11:37:11AM +0100, Phil Sutter wrote:
> When trying to add a rule which contains an anonymous chain to a
> non-existent chain, string_misspell_update() is called with a NULL
> string because the anonymous chain has no name. Avoid this by making the
> function NULL-pointer tolerant.
> 
> c330152b7f777 ("src: support for implicit chain bindings")
> 
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
>  src/misspell.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/misspell.c b/src/misspell.c
> index 6536d7557a445..f213a240005e6 100644
> --- a/src/misspell.c
> +++ b/src/misspell.c
> @@ -80,8 +80,8 @@ int string_misspell_update(const char *a, const char *b,
>  {
>  	unsigned int len_a, len_b, max_len, min_len, distance, threshold;
>  
> -	len_a = strlen(a);
> -	len_b = strlen(b);
> +	len_a = a ? strlen(a) : 0;
> +	len_b = b ? strlen(b) : 0;

string_distance() assumes non-NULL too.

probably shortcircuit chain_lookup_fuzzy() earlier since h->chain.name
is always NULL, to avoid the useless loop.

Patch attached.

>  	max_len = max(len_a, len_b);
>  	min_len = min(len_a, len_b);
> -- 
> 2.34.1
> 

[-- Attachment #2: x.patch --]
[-- Type: text/x-diff, Size: 376 bytes --]

diff --git a/src/rule.c b/src/rule.c
index b1700c40079d..19b8cb0323ee 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -758,6 +758,9 @@ struct chain *chain_lookup_fuzzy(const struct handle *h,
 	struct table *table;
 	struct chain *chain;
 
+	if (!h->chain.name)
+		return NULL;
+
 	string_misspell_init(&st);
 
 	list_for_each_entry(table, &cache->table_cache.list, cache.list) {

  reply	other threads:[~2022-03-04 11:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-04 10:37 [nft PATCH] misspell: Avoid segfault with anonymous chains Phil Sutter
2022-03-04 11:11 ` Pablo Neira Ayuso [this message]
2022-03-04 12:15   ` Phil Sutter
2022-03-07 21:08     ` 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=YiHz+bNsLvFjkPit@salvia \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=phil@nwl.cc \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.