Author: jilles
Date: Sat Feb  5 21:24:37 2011
New Revision: 218346
URL: http://svn.freebsd.org/changeset/base/218346

Log:
  MFC r216496: 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:
  stable/8/tools/regression/bin/sh/expansion/cmdsubst3.0
     - copied unchanged from r216496, 
head/tools/regression/bin/sh/expansion/cmdsubst3.0
Modified:
  stable/8/bin/sh/expand.c
Directory Properties:
  stable/8/bin/sh/   (props changed)
  stable/8/tools/regression/bin/sh/   (props changed)

Modified: stable/8/bin/sh/expand.c
==============================================================================
--- stable/8/bin/sh/expand.c    Sat Feb  5 21:21:27 2011        (r218345)
+++ stable/8/bin/sh/expand.c    Sat Feb  5 21:24:37 2011        (r218346)
@@ -470,8 +470,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 {
@@ -479,6 +477,8 @@ expbackq(union node *cmd, int quoted, in
                                        nnl--;
                                        STPUTC('\n', dest);
                                }
+                               if (quotes && syntax[(int)lastc] == CCTL)
+                                       STPUTC(CTLESC, dest);
                                STPUTC(lastc, dest);
                        }
                }

Copied: stable/8/tools/regression/bin/sh/expansion/cmdsubst3.0 (from r216496, 
head/tools/regression/bin/sh/expansion/cmdsubst3.0)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/expansion/cmdsubst3.0      Sat Feb  5 
21:24:37 2011        (r218346, copy of r216496, 
head/tools/regression/bin/sh/expansion/cmdsubst3.0)
@@ -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
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to