[patch 01/37] TEXTSEARCH: Fix Boyer Moore initialization bug

Greg KH
2006-09-06T23:14:43Z

[-- Attachment #1: textsearch-fix-boyer-moore-initialization-bug.patch --]
[-- Type: text/plain, Size: 1678 bytes --]

-stable review patch. If anyone has any objections, please let us know.

------------------

From: Michael Rash <mbr@cipherdyne.org>

[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@cipherdyne.org>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Acked-by: David Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
lib/ts_bm.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

--- linux-2.6.17.11.orig/lib/ts_bm.c
+++ linux-2.6.17.11/lib/ts_bm.c
@@ -112,15 +112,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 */
@@ -151,8 +150,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;
}

--