summaryrefslogtreecommitdiff
path: root/lib/libc/regex/engine.c
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2004-04-02 18:34:34 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2004-04-02 18:34:34 +0000
commitc6d7aa1d252c72b8d25deb202b6056f8b873cd66 (patch)
treebb00466f158d70aab60176524edf5e603af83bf7 /lib/libc/regex/engine.c
parente96d1af3c8261b0965c7633f833d72d82bc2a119 (diff)
Avoid unbounded recursion in some expressions involving back references.
For example: echo "foo foo bar bar bar baz" | sed 's/\([^ ]*\)\( *\1\)*/\1/g' Test case found by dhartmei@ ok millert@ dhartmei@ tedu@
Diffstat (limited to 'lib/libc/regex/engine.c')
-rw-r--r--lib/libc/regex/engine.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/libc/regex/engine.c b/lib/libc/regex/engine.c
index cafa1bb65b3..9f24b201a2a 100644
--- a/lib/libc/regex/engine.c
+++ b/lib/libc/regex/engine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.c,v 1.8 2004/03/30 20:36:07 millert Exp $ */
+/* $OpenBSD: engine.c,v 1.9 2004/04/02 18:34:33 otto Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
@@ -36,7 +36,7 @@
*/
#if defined(SNAMES) && defined(LIBC_SCCS) && !defined(lint)
-static char enginercsid[] = "$OpenBSD: engine.c,v 1.8 2004/03/30 20:36:07 millert Exp $";
+static char enginercsid[] = "$OpenBSD: engine.c,v 1.9 2004/04/02 18:34:33 otto Exp $";
#endif /* SNAMES and LIBC_SCCS and not lint */
/*
@@ -607,6 +607,8 @@ sopno lev; /* PLUS nesting level */
return(NULL);
assert(m->pmatch[i].rm_so != -1);
len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so;
+ if (len == 0)
+ return(NULL);
assert(stop - m->beginp >= len);
if (sp > stop - len)
return(NULL); /* not enough left to match */