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:
Hiroki Sato 2008-11-09 01:10:21 +00:00
parent 5bbae50149
commit d3d0d3a3b5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=184777

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