summaryrefslogtreecommitdiffstats
path: root/lib/libc/regex/engine.c
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2016-05-25 20:48:22 +0000
committerschwarze <schwarze@openbsd.org>2016-05-25 20:48:22 +0000
commit1ca78303dccb2bf8b2185fe553ca3d10ba6d750b (patch)
tree027747f66478cce162a431bae551b124624720bf /lib/libc/regex/engine.c
parentMust extract uvm_vnode from uvm_object first before reading the vnode (diff)
downloadwireguard-openbsd-1ca78303dccb2bf8b2185fe553ca3d10ba6d750b.tar.xz
wireguard-openbsd-1ca78303dccb2bf8b2185fe553ca3d10ba6d750b.zip
Fix another one-byte buffer underflow (read access only).
This change touches code that only runs when REG_BASIC is given and the regular expression is anchored with [[:<:]] or \< _and_ uses backreferences. Simplify the logic while here, already looking at the previous character if REG_STARTEND and REG_NOTBOL are both in use, in anticipation of martijn@'s upcoming patch which will further improve REG_STARTEND. OK millert@ martijn@ Also tested by Pedro Giffuni (pfg) on FreeBSD.
Diffstat (limited to 'lib/libc/regex/engine.c')
-rw-r--r--lib/libc/regex/engine.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/libc/regex/engine.c b/lib/libc/regex/engine.c
index b21928bbf99..6b99b1c3071 100644
--- a/lib/libc/regex/engine.c
+++ b/lib/libc/regex/engine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.c,v 1.20 2016/05/17 22:03:18 schwarze Exp $ */
+/* $OpenBSD: engine.c,v 1.21 2016/05/25 20:48:22 schwarze Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
@@ -522,12 +522,9 @@ backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst,
return(NULL);
break;
case OBOW:
- if (( (sp == m->beginp && !(m->eflags&REG_NOTBOL)) ||
- (sp < m->endp && *(sp-1) == '\n' &&
- (m->g->cflags&REG_NEWLINE)) ||
- (sp > m->beginp &&
- !ISWORD(*(sp-1))) ) &&
- (sp < m->endp && ISWORD(*sp)) )
+ if (sp < m->endp && ISWORD(*sp) &&
+ ((sp == m->beginp && !(m->eflags&REG_NOTBOL)) ||
+ (sp > m->offp && !ISWORD(*(sp-1)))))
{ /* yes */ }
else
return(NULL);