summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2020-11-16 10:03:39 -0500
committerZack Weinberg <zackw@panix.com>2020-11-16 10:03:39 -0500
commitb7e32b4dc746ea867ed68f41d767178b34cc43a0 (patch)
tree2a176b73db79b5466b3177bb9c788c4f41b33fc8 /tests
parent15acc26a209accd353f5961487dfef3a03e12b4a (diff)
downloadautoconf-b7e32b4dc746ea867ed68f41d767178b34cc43a0.tar.gz
AS_ECHO(_N): Do not expand macros named ‘s’ or ‘n’ (#110377)
AS_ECHO expands to ‘printf "%s\n" $1’. If a configure script defines an M4 macro named ‘s’ or ‘n’ it will be expanded in the first argument to printf, which is almost certainly not what was intended. The configure script for ruby 2.7.2 uses ‘AS_VAR_PUSHDEF([s], ...)’ and breaks with 2.69d because of this. Add some extra quoting so that the ‘%s\n’ is treated as literal; similarly for AS_ECHO_N and the legacy shell variables $as_echo and $as_echo_n. For now, anyway, don’t quote the word ‘printf’; if someone does define that as a M4 macro they might well mean to affect AS_ECHO. (Whether this is something we *want* to allow, we can worry about when it comes up.) Fixes bug #110377. * lib/m4sugar/m4sh.m4 (_AS_ECHO_N_PREPARE, AS_ECHO, AS_ECHO_N): Add another layer of quoting around the first argument to printf. * tests/m4sh.at (Redefining AS_ECHO internals): New test.
Diffstat (limited to 'tests')
-rw-r--r--tests/m4sh.at90
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/m4sh.at b/tests/m4sh.at
index 21c61237..6504b71a 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -636,6 +636,96 @@ AT_CHECK([$CONFIG_SHELL ./script])
AT_CLEANUP
+## ------------------------------ ##
+## Redefining AS_ECHO internals. ##
+## ------------------------------ ##
+
+AT_SETUP([Redefining AS@&t@_ECHO internals])
+
+# None of the tests below do any AC_DEFINEs, so running autoheader is
+# a waste of time, but the skeleton generated by AT_CONFIGURE_AC needs
+# this file to exist anyway.
+AT_DATA([config.hin])
+
+# Defining a macro named `s' or `n' should not affect AS_ECHO or
+# macros that use it.
+
+AT_CONFIGURE_AC(
+[[m4@&t@_pushdef([s], [z])
+m4@&t@_pushdef([n], [u])
+AC_MSG_NOTICE([checking whether m4sugar echo works... yes])
+AC_MSG_CHECKING([whether m4sugar echo_n works])
+AC_MSG_RESULT([yes])
+m4@&t@_popdef([s])
+m4@&t@_popdef([n])
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE([], [],
+[[configure: checking whether m4sugar echo works... yes
+checking whether m4sugar echo_n works... yes
+configure: creating ./config.status
+config.status: creating config.h
+]], [])
+AT_CHECK_ENV
+rm config.h
+
+# More elaborate version of the above; derived from actual code in
+# ruby 2.7.2's configure script.
+
+AT_CONFIGURE_AC(
+[[AC@&t@_DEFUN([RUBY_CHECK_SIZEOF],[
+AS@&t@_VAR_PUSHDEF([s], [ac_cv_sizeof_size])
+AC@&t@_CACHE_CHECK([size of $1],
+ [AS@&t@_TR_SH([ac_cv_sizeof_$1])],
+ [AS@&t@_TR_SH(ac_cv_sizeof_$1)=1])
+
+# fake use of 's' for illustratve purposes:
+s=42
+echo "s is defined as ${s}"
+
+AS@&t@_VAR_POPDEF([s])
+])
+
+RUBY_CHECK_SIZEOF(int)
+echo "ac_cv_sizeof_int=${ac_cv_sizeof_int}"
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE([], [],
+[[checking size of int... 1
+ac_cv_sizeof_size is defined as 42
+ac_cv_sizeof_int=1
+configure: creating ./config.status
+config.status: creating config.h
+]], [])
+AT_CHECK_ENV
+rm config.h
+
+# However, defining a macro named `printf' _is_ expected to affect
+# the functioning of AS_ECHO.
+
+AT_CONFIGURE_AC(
+[[m4@&t@_pushdef([printf], [echo])
+AC_MSG_NOTICE([checking whether m4sugar echo works... yes])
+AC_MSG_CHECKING([whether m4sugar echo_n works])
+AC_MSG_RESULT([yes])
+m4@&t@_popdef([printf])
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE([], [],
+[[%s\n configure: checking whether m4sugar echo works... yes
+%s checking whether m4sugar echo_n works... @&t@
+%s\n yes
+configure: creating ./config.status
+config.status: creating config.h
+]], [])
+AT_CHECK_ENV
+
+AT_CLEANUP
+
+
## ----------------- ##
## AS_EXECUTABLE_P. ##
## ----------------- ##