summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2003-07-01 00:09:23 +0000
committermillert <millert@openbsd.org>2003-07-01 00:09:23 +0000
commit885eca2a800fd1a8230e37f722ce0e3ac978448b (patch)
tree119444ee03ee201ab461df704bd43a221e501477
parentAwk first appeared in appeared in Version 7 AT&T UNIX. (diff)
downloadwireguard-openbsd-885eca2a800fd1a8230e37f722ce0e3ac978448b.tar.xz
wireguard-openbsd-885eca2a800fd1a8230e37f722ce0e3ac978448b.zip
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@.
-rw-r--r--usr.bin/grep/util.c7
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. */