>From b331bbaf4eb0581fce24f078561283e3616398f8 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 23 Sep 2022 02:36:48 +0200 Subject: [PATCH] syscmd: Make it work again for most commands on FreeBSD and AIX. * src/builtin.c (m4_syscmd): Use "sh -c -- $cmd" only if $cmd starts with '-' or '+'. --- src/builtin.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/builtin.c b/src/builtin.c index 0715a332..0180d625 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -947,7 +947,7 @@ m4_syscmd (struct obstack *obs MAYBE_UNUSED, int argc, token_data **argv) const char *cmd = ARG (1); int status; int sig_status; - int slot = 3; + int slot; const char *prog_args[5] = { "sh", "-c", "--" }; if (bad_argc (argv[0], argc, 2, 2) || !*cmd) { @@ -964,8 +964,23 @@ m4_syscmd (struct obstack *obs MAYBE_UNUSED, int argc, token_data **argv) prog_args[1] = "/c"; slot = 2; } + else #endif + { + if (cmd[0] == '-' || cmd[0] == '+') + /* If cmd starts with '-' or '+', "sh -c $cmd" is not guaranteed to + work. In this case, use "sh -c -- $cmd". + Note: This requires a POSIX compliant SYSCMD_SHELL. It does not + work with /bin/sh on FreeBSD 13 and AIX 7, and on these platforms + 'bash' is not guaranteed to be installed. */ + slot = 3; + else + /* For most commands, the traditional "sh -c $cmd" works fine. + Including on FreeBSD 13 and AIX 7. */ + slot = 2; + } prog_args[slot] = cmd; + prog_args[slot + 1] = NULL; errno = 0; status = execute (ARG (0), SYSCMD_SHELL, prog_args, NULL, false, false, false, false, true, false, &sig_status); -- 2.34.1