Hi,

attached please find a patch which checks for the ksh93f bug in
expanding here-documents.

I understand that changing the better shell routine might be
dangerous; but it is less dangerous in this case:

Ralf made a quick search and it seems that the UnixWare was the only
one having that among the candidates for a better shell.
(Solaris has it under the name `dtksh' and AIX under the name
`ksh93'.)

On Fri, May 26, 2006 at 10:24:09AM -0700, Paul Eggert wrote:
> The problem isn't dtksh; it is systems that use, or plan to use, ksh93
> under some name like 'ksh' or 'sh'.  This could well be more of a
> problem in the near future.

I think this was written before Ralf found out that ksh93g fixes the
bug.

To sum up, I believe my check won't stir up the better shell
selection too much.  Dear ``release engineer'' would you consider
installing it now?

In any case, I believe we need it in the long run: the bug is mean,
hard to identify, and it is possible that it will hit an innocent
user who has a long here-document in his configure.ac.

The patch also contains some sharpening of the documentation
describing the bug.  Is the wording OK?

Have a nice day,
        Stepan
2006-06-02  Stepan Kasal  <[EMAIL PROTECTED]>

        * lib/m4sugar/m4sh.m4 (_AS_HERE_DOC_WORKS): Check for the
        ksh93f bug with long here-documents.
        (AS_INIT): Require this check.
        * doc/autoconf.texi (Here-Documents): Add more details about
        the bug.

Index: lib/m4sugar/m4sh.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/m4sugar/m4sh.m4,v
retrieving revision 1.190
diff -u -r1.190 m4sh.m4
--- lib/m4sugar/m4sh.m4 31 May 2006 09:44:39 -0000      1.190
+++ lib/m4sugar/m4sh.m4 2 Jun 2006 11:37:00 -0000
@@ -1459,6 +1459,31 @@
 }
 ])
 
+# _AS_HERE_DOC_WORKS
+# ------------------
+# ksh versions prior to ksh93g mishandle braced variable expansion in
+# non-quoted here-documents, if the variable name crosses a block boundary
+# (block can be 1024 or 4096 bytes).  Check for this.
+#
+m4_define([_AS_HERE_DOC_WORKS], [
+# (2^6 - 1) dots
+as_d=...............................................................
+# (2^9 - 1) characters
+as_d="$as_d:$as_d:$as_d:$as_d
+$as_d:$as_d:$as_d:$as_d"
+$as_shell >/dev/null 2>&1 <<_ASOUTER
+foobar=OK
+bar=BAD
+# the first two lines expand to (2^12 - 6) characters (including the two
+# trailing newlines), so the 4096 boundary appears between "{foo" and "bar}"
+grep OK <<_ASINNER
+$as_d$as_d$as_d$as_d
+$as_d$as_d$as_d$as_d
+ \${foobar}
+_ASINNER
+_ASOUTER
+])
+
 
 # AS_INIT
 # -------
@@ -1473,6 +1498,7 @@
 m4_divert_text([BINSH], [EMAIL PROTECTED]:@! /bin/sh])
 m4_divert_text([M4SH-SANITIZE], [AS_SHELL_SANITIZE])
 AS_REQUIRE([_AS_SHELL_FN_SPY])
+_AS_DETECT_REQUIRED([_AS_HERE_DOC_WORKS])
 
 # Let's go!
 m4_wrap([m4_divert_pop([BODY])[]])
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.1033
diff -u -r1.1033 autoconf.texi
--- doc/autoconf.texi   1 Jun 2006 07:47:40 -0000       1.1033
+++ doc/autoconf.texi   2 Jun 2006 12:28:40 -0000
@@ -10792,11 +10792,14 @@
 inefficiently.  And some shells mishandle large here-documents: for example,
 Solaris 10 @command{dtksh} and the UnixWare 7.1.1 Posix shell, which are
 derived from Korn shell version M-12/28/93d, mishandle braced variable
-expansion @[EMAIL PROTECTED]@}} that crosses a 1024- or 4096-byte buffer 
boundary
-within a here-document.  If the closing brace does not lie on the boundary,
-the failure is silent and the variable expansion will be empty, otherwise
-the shell will report a bad substitution.  This bug can usually be worked
-around by omitting the braces: @code{$var}.  The bug was fixed in
+expansion that crosses a 1024- or 4096-byte buffer boundary
+within a here-document.  Only the part of the variable name after the boundary
+is used.  For example, @[EMAIL PROTECTED]@}} could be replaced by the expansion
+of @[EMAIL PROTECTED]@}}.  If the end of the variable name is aligned with the 
block
+boundary, the shell reports an error, as if you used @[EMAIL PROTECTED]@}}.
+Instead of @[EMAIL PROTECTED]@}}, the shell may expand
[EMAIL PROTECTED]@[EMAIL PROTECTED], or even @[EMAIL PROTECTED]@}}.  This bug 
can usually
+be worked around by omitting the braces: @code{$var}.  The bug was fixed in
 @samp{ksh93g} (1998-04-30) but as of 2006 many operating systems were
 still shipping older versions with the bug.
 

Reply via email to