summaryrefslogtreecommitdiffstats
path: root/lib/libc/regex/engine.c
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2004-04-02 18:34:33 +0000
committerotto <otto@openbsd.org>2004-04-02 18:34:33 +0000
commit2617cd22e38992f4cc44590298b0c107826d1059 (patch)
treefe34ee82ecd95750257b20c2265f9a2528f07d28 /lib/libc/regex/engine.c
parentspelink (diff)
downloadwireguard-openbsd-2617cd22e38992f4cc44590298b0c107826d1059.tar.xz
wireguard-openbsd-2617cd22e38992f4cc44590298b0c107826d1059.zip
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 */