summaryrefslogtreecommitdiff
path: root/usr.bin/grep/util.c
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2005-04-03 19:12:41 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2005-04-03 19:12:41 +0000
commit90dbf46dcc517309179b2d183d29024aaa424174 (patch)
tree9e86f4d913b3c72ef30c4054f5f27500133a1f3a /usr.bin/grep/util.c
parent2a84335088b17863bfb6ba7b15f23c512855adbb (diff)
Protect begin and end of word markers added to the pattern when
using the -w option with parentheses, to avoid operators in the expressions binding to the markers. Compare [[:<:]]foo|bar[[:>:]] and [[:<:]](foo|bar)[[:>:]]. Problem spotted by aaron@; ok millert@ aaron@ jaredy@
Diffstat (limited to 'usr.bin/grep/util.c')
-rw-r--r--usr.bin/grep/util.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index f168fe5ae90..1f93e9ef632 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.29 2004/10/03 19:23:02 otto Exp $ */
+/* $OpenBSD: util.c,v 1.30 2005/04/03 19:12:40 otto Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -302,7 +302,12 @@ fastcomp(fastgrep_t *fg, const char *pattern)
}
/* Remove enclosing [[:<:]] and [[:>:]] (word match). */
- if (fg->patternLen >= 14 &&
+ if (wflag) {
+ /* basic re's use \( \), extended re's ( ) */
+ int extra = Eflag ? 1 : 2;
+ fg->patternLen -= 14 + 2 * extra;
+ fg->wmatch = 7 + extra;
+ } else if (fg->patternLen >= 14 &&
strncmp(pattern + fg->bol, "[[:<:]]", 7) == 0 &&
strncmp(pattern + fg->bol + fg->patternLen - 7, "[[:>:]]", 7) == 0) {
fg->patternLen -= 14;