[TEXTSEARCH]: Fix Boyer Moore initialization bug
Patrick McHardy
kaber at trash.net
Tue Aug 22 04:07:57 CEST 2006
Hi Dave,
this fixes an initialization bug in the bm textsearch
algorithm affecting the netfilter string match (the
only user AFAIK). Please apply to 2.6.18, thanks.
@stable maintainers: the bm_ts author asked me to also
submit this to -stable, please apply.
-------------- next part --------------
[TEXTSEARCH]: Fix Boyer Moore initialization bug
The pattern is set after trying to compute the prefix table, which tries
to use it. Initialize it before calling compute_prefix_tbl, make
compute_prefix_tbl consistently use only the data from struct ts_bm
and remove the now unnecessary arguments.
Signed-off-by: Michael Rash <mbr at cipherdyne.org>
Signed-off-by: Patrick McHardy <kaber at trash.net>
---
commit 96d2404fab775fc7aebf06956bd3ea5e8996b0f7
tree 682dee25bd20e0d85f909fbf5967db2844d58253
parent 8ebd6bb0f469f2759f39e73adee6916a3d975393
author Michael Rash <mbr at cipherdyne.org> Thu, 17 Aug 2006 17:43:21 +0200
committer Patrick McHardy <kaber at trash.net> Thu, 17 Aug 2006 17:43:21 +0200
lib/ts_bm.c | 11 +++++------
1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/lib/ts_bm.c b/lib/ts_bm.c
index 0110e44..d90822c 100644
--- a/lib/ts_bm.c
+++ b/lib/ts_bm.c
@@ -111,15 +111,14 @@ static int subpattern(u8 *pattern, int i
return ret;
}
-static void compute_prefix_tbl(struct ts_bm *bm, const u8 *pattern,
- unsigned int len)
+static void compute_prefix_tbl(struct ts_bm *bm)
{
int i, j, g;
for (i = 0; i < ASIZE; i++)
- bm->bad_shift[i] = len;
- for (i = 0; i < len - 1; i++)
- bm->bad_shift[pattern[i]] = len - 1 - i;
+ bm->bad_shift[i] = bm->patlen;
+ for (i = 0; i < bm->patlen - 1; i++)
+ bm->bad_shift[bm->pattern[i]] = bm->patlen - 1 - i;
/* Compute the good shift array, used to match reocurrences
* of a subpattern */
@@ -150,8 +149,8 @@ static struct ts_config *bm_init(const v
bm = ts_config_priv(conf);
bm->patlen = len;
bm->pattern = (u8 *) bm->good_shift + prefix_tbl_len;
- compute_prefix_tbl(bm, pattern, len);
memcpy(bm->pattern, pattern, len);
+ compute_prefix_tbl(bm);
return conf;
}
More information about the netfilter-devel
mailing list