From 0f4481c5e4fbc94727ae9ab2cde6a325aaf52d3d Mon Sep 17 00:00:00 2001 From: Xin LI Date: Mon, 5 Mar 2007 03:07:36 +0000 Subject: [PATCH] Avoid infinite recursion on: echo "foo foo bar bar bar baz" | sed 's/\([^ ]*\)\( *\1\)*/\1/g' Obtained from: OpenBSD via NetBSD (rev. 1.18) --- lib/libc/regex/engine.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/libc/regex/engine.c b/lib/libc/regex/engine.c index b8c8f49163c9..9c09efae6fa6 100644 --- a/lib/libc/regex/engine.c +++ b/lib/libc/regex/engine.c @@ -674,6 +674,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 */