Linux Netfilter development
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Finke Lennart <lfinke@student.ethz.ch>
Cc: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux@vger.kernel.org" <linux@vger.kernel.org>,
	"netfilter-devel@vger.kernel.org"
	<netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH] lib/ts_bm: fix missed matches with TS_IGNORECASE
Date: Tue, 27 Oct 2026 19:22:17 +0100	[thread overview]
Message-ID: <auDr2Yb1WzBA5Gv-@chamomile> (raw)
In-Reply-To: <48F87C26-7D3C-490B-ADA1-2FB0E3E10F53@student.ethz.ch>

On Tue, Oct 27, 2026 at 05:20:20PM +0000, Finke  Lennart wrote:
> With TS_IGNORECASE the pattern is stored upper-cased, but bm_find()
> looks up bad_shift[] with the raw text byte. The extra tolower()
> entries miss bytes like 0xff and 0xdf, whose toupper() is a different
> byte that lower-cases to itself, so matches are skipped: "\xffZ" is not
> found in "Y\xffZ".
> 
> Fold the text byte with toupper() before the lookup and drop the
> tolower() entries.

Better to handle this from configuration time.

> Fixes: 3b76d08190e6 ("textsearch: ts_bm: support case insensitive searching in Boyer-Moore algorithm")
> Cc: stable@vger.kernel.org
> Signed-off-by: Lennart Finke <lfinke@ethz.ch>
> ---
>  lib/ts_bm.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/ts_bm.c b/lib/ts_bm.c
> index 676105e84005..f809aa05f5fc 100644
> --- a/lib/ts_bm.c
> +++ b/lib/ts_bm.c
> @@ -101,7 +101,8 @@ static unsigned int bm_find(struct ts_config *conf, struct ts_state *state)
>  				return consumed + (shift-(bm->patlen-1));
>  			}
>  
> -			bs = bm->bad_shift[text[shift-i]];
> +			bs = bm->bad_shift[icase ? toupper(text[shift-i]) :
> +						   text[shift-i]];
>  
>  			/* Now jumping to... */
>  			shift = max_t(int, shift-i+bs, shift+bm->good_shift[i]);
> @@ -130,18 +131,14 @@ static int subpattern(u8 *pattern, int i, int j, int g)
>  	return ret;
>  }
>  
> -static void compute_prefix_tbl(struct ts_bm *bm, int flags)
> +static void compute_prefix_tbl(struct ts_bm *bm)
>  {
>  	int i, j, g;
>  
>  	for (i = 0; i < ASIZE; i++)
>  		bm->bad_shift[i] = bm->patlen;
> -	for (i = 0; i < bm->patlen - 1; i++) {
> +	for (i = 0; i < bm->patlen - 1; i++)
>  		bm->bad_shift[bm->pattern[i]] = bm->patlen - 1 - i;
> -		if (flags & TS_IGNORECASE)
> -			bm->bad_shift[tolower(bm->pattern[i])]
> -			    = bm->patlen - 1 - i;
> -	}
>  
>  	/* Compute the good shift array, used to match reocurrences 
>  	 * of a subpattern */
> @@ -193,7 +190,7 @@ static struct ts_config *bm_init(const void *pattern, unsigned int len,
>  			bm->pattern[i] = toupper(((u8 *)pattern)[i]);
>  	else
>  		memcpy(bm->pattern, pattern, len);
> -	compute_prefix_tbl(bm, flags);
> +	compute_prefix_tbl(bm);
>  
>  	return conf;
>  }
> 
> base-commit: 21a7f44fd0765fcc5194130b28767786eba1d1e7
> -- 
> 2.50.1 (Apple Git-155)
> 
> 

      reply	other threads:[~2026-10-27 18:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 17:20 [PATCH] lib/ts_bm: fix missed matches with TS_IGNORECASE Finke  Lennart
2026-10-27 18:22 ` Pablo Neira Ayuso [this message]

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=auDr2Yb1WzBA5Gv-@chamomile \
    --to=pablo@netfilter.org \
    --cc=akpm@linux-foundation.org \
    --cc=lfinke@student.ethz.ch \
    --cc=linux@vger.kernel.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