diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-07-01 00:09:24 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-07-01 00:09:24 +0000 |
commit | 56b59da7980e32b41ebc032a9a5697640184adb8 (patch) | |
tree | f95fd127036a1dbdf7a35c81339ea76067cde965 /usr.bin/grep | |
parent | 90e64e544740b806a7e36210664d121ea0c8721f (diff) |
Fix bounds check in the fast grep code that caused an incorrect
array access (and a core dump on sparc64 at least). Noticed by
sturm@ and pvalchev@. Fix tested an OK by pvalchev@.
Diffstat (limited to 'usr.bin/grep')
-rw-r--r-- | usr.bin/grep/util.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index a94b2d602ca..9b0b0aee45d 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.11 2003/06/25 17:28:00 millert Exp $ */ +/* $OpenBSD: util.c,v 1.12 2003/07/01 00:09:23 millert Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -412,10 +412,9 @@ grep_search(fastgrep_t *fg, unsigned char *data, int dataLen, regmatch_t *pmatch } /* Shift if within bounds, otherwise, we are done. */ - if (j == 0) + if (j - fg->patternLen - 1 < 0) break; - else - j -= fg->qsBc[data[j - fg->patternLen - 1]]; + j -= fg->qsBc[data[j - fg->patternLen - 1]]; } while (j >= 0); } else { /* Quick Search algorithm. */ |