[git commit] sed: fix breakage added by zero length match code

Denys Vlasenko vda.linux at googlemail.com
Thu Jun 7 14:34:57 UTC 2012


commit: http://git.busybox.net/busybox/commit/?id=84406e459be31b89de5a3d822f205d61c4c5855b
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 editors/sed.c       |    2 +-
 testsuite/sed.tests |    4 ++++
 2 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/editors/sed.c b/editors/sed.c
index 85c8466..0fe82f3 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -767,7 +767,7 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p)
 		 * second is "" before "d", third is "" after "d".
 		 * Second match is NOT replaced!
 		 */
-		if (prev_match_empty || start != 0) {
+		if (prev_match_empty || start != 0 || start != end) {
 			dbg("inserting replacement at %d in '%s'", start, line);
 			do_subst_w_backrefs(line, sed_cmd->string);
 		} else {
diff --git a/testsuite/sed.tests b/testsuite/sed.tests
index 375beb5..12b36ae 100755
--- a/testsuite/sed.tests
+++ b/testsuite/sed.tests
@@ -302,6 +302,10 @@ testing "sed zero chars match/replace advances correctly 2" \
 	"sed 's [^ .]* x g'" \
 	"x x.x\n" "" " a.b\n"
 
+testing "sed zero chars match/replace logic must not falsely trigger here" \
+	"sed 's/a/A/g'" \
+	"_AAA1AA\n" "" "_aaa1aa\n"
+
 # testing "description" "commands" "result" "infile" "stdin"
 
 exit $FAILCOUNT


More information about the busybox-cvs mailing list