Add workaround for a back reference when no corresponding

parenthesized subexpression is defined.  For example, the
following command line caused unexpected behavior like
segmentation fault:

 % echo test | sed -e 's/test/\1/'

PR:		bin/126682
MFC after:	1 week
This commit is contained in:
hrs 2008-11-09 01:10:21 +00:00
parent c3eca8b8cc
commit 9fe9cedf42

View File

@ -324,9 +324,17 @@ semicolon: EATSPACE();
if (p == NULL)
errx(1,
"%lu: %s: unterminated substitute pattern", linenum, fname);
/* Compile RE with no case sensitivity temporarily */
if (*re == '\0')
cmd->u.s->re = NULL;
else
cmd->u.s->re = compile_re(re, 0);
--p;
p = compile_subst(p, cmd->u.s);
p = compile_flags(p, cmd->u.s);
/* Recompile RE with case sensitivity from "I" flag if any */
if (*re == '\0')
cmd->u.s->re = NULL;
else