summaryrefslogtreecommitdiff
path: root/lib
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 /lib
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 'lib')
-rw-r--r--lib/m4sugar/m4sh.m417
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 81b3f82e..9d543952 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -897,8 +897,11 @@ esac
# the shell variables $as_echo and $as_echo_n. New code should use
# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively.
dnl The @&t@ prevents a spurious deprecation diagnostic.
-as_@&t@echo='printf %s\n'
-as_@&t@echo_n='printf %s'
+dnl Extra quoting in case `s' or `n' are user-defined macros when this
+dnl is expanded; they almost certainly aren't meant to be used here.
+dnl See bug 110377.
+as_@&t@echo='printf [%s\n]'
+as_@&t@echo_n='printf [%s]'
])# _AS_ECHO_N_PREPARE
@@ -1106,7 +1109,10 @@ fi
# (typically a quoted string). The bytes of WORD are output as-is, even
# if it starts with "-" or contains "\".
m4_define([AS_ECHO],
-[printf "%s\n" $1])
+dnl Extra quoting in case `s' or `n' are user-defined macros when this
+dnl is expanded; they almost certainly aren't meant to be used here.
+dnl See bug 110377.
+[printf "[%s\n]" $1])
# Deprecation warning for the former internal shell variable $as_echo.
m4_define([as_echo],
@@ -1118,7 +1124,10 @@ m4_define([as_echo],
# ---------------
# Like AS_ECHO(WORD), except do not output the trailing newline.
m4_define([AS_ECHO_N],
-[printf %s $1])
+dnl Extra quoting in case `s' is a user-defined macro when this
+dnl is expanded; it almost certainly isn't meant to be used here.
+dnl See bug 110377.
+[printf [%s] $1])
# Deprecation warning for the former internal shell variable $as_echo_n.
m4_define([as_echo_n],