svn commit: r216496 - in head: bin/sh
tools/regression/bin/sh/expansion
Jilles Tjoelker
jilles at FreeBSD.org
Thu Dec 16 23:28:20 UTC 2010
Author: jilles
Date: Thu Dec 16 23:28:20 2010
New Revision: 216496
URL: http://svn.freebsd.org/changeset/base/216496
Log:
sh: Fix corruption of command substitutions with special chars after newline
The CTLESC byte to protect a special character was output before instead of
after a newline directly preceding the special character.
The special handling of newlines is because command substitutions discard
all trailing newlines.
Added:
head/tools/regression/bin/sh/expansion/cmdsubst3.0 (contents, props changed)
Modified:
head/bin/sh/expand.c
Modified: head/bin/sh/expand.c
==============================================================================
--- head/bin/sh/expand.c Thu Dec 16 21:01:02 2010 (r216495)
+++ head/bin/sh/expand.c Thu Dec 16 23:28:20 2010 (r216496)
@@ -499,8 +499,6 @@ expbackq(union node *cmd, int quoted, in
}
lastc = *p++;
if (lastc != '\0') {
- if (quotes && syntax[(int)lastc] == CCTL)
- STPUTC(CTLESC, dest);
if (lastc == '\n') {
nnl++;
} else {
@@ -508,6 +506,8 @@ expbackq(union node *cmd, int quoted, in
nnl--;
STPUTC('\n', dest);
}
+ if (quotes && syntax[(int)lastc] == CCTL)
+ STPUTC(CTLESC, dest);
STPUTC(lastc, dest);
}
}
Added: head/tools/regression/bin/sh/expansion/cmdsubst3.0
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/tools/regression/bin/sh/expansion/cmdsubst3.0 Thu Dec 16 23:28:20 2010 (r216496)
@@ -0,0 +1,20 @@
+# $FreeBSD$
+
+e=
+for i in 0 1 2 3; do
+ for j in 0 1 2 3 4 5 6 7; do
+ for k in 0 1 2 3 4 5 6 7; do
+ case $i$j$k in
+ 000) continue ;;
+ esac
+ e="$e\n\\$i$j$k"
+ done
+ done
+done
+e1=$(printf "$e")
+e2="$(printf "$e")"
+[ "${#e1}" = 510 ] || echo length bad
+[ "$e1" = "$e2" ] || echo e1 != e2
+[ "$e1" = "$(printf "$e")" ] || echo quoted bad
+IFS=
+[ "$e1" = $(printf "$e") ] || echo unquoted bad
More information about the svn-src-head
mailing list