Don't strip quotes from exec args

Before passing a command to a command handler the quotes are stripped
from each argument in the command. This is usually the wanted behavior
but causes a problem in the case of `exec` where quoted arguments can be
required when passing the exec command to `/bin/sh -c`.

This patch makes `exec` a special case and doesn't strip quotes from the
arguments. It will just pass the exec command verbatim to the exec
command handler.

Fix #518
This commit is contained in:
Mikkel Oscar Lyderik 2016-03-18 09:34:45 +01:00
parent e7e1081a93
commit 99f26c61a5

View file

@ -362,10 +362,8 @@ static struct cmd_results *cmd_exec_always(int argc, char **argv) {
return error; return error;
} }
add_quotes(argv + 1, argc - 1);
tmp = join_args(argv + 1, argc - 1); tmp = join_args(argv + 1, argc - 1);
} else { } else {
add_quotes(argv, argc);
tmp = join_args(argv, argc); tmp = join_args(argv, argc);
} }
@ -2869,10 +2867,12 @@ struct cmd_results *handle_command(char *_exec) {
//TODO better handling of argv //TODO better handling of argv
int argc; int argc;
char **argv = split_args(cmd, &argc); char **argv = split_args(cmd, &argc);
int i; if (strcmp(argv[0], "exec") != 0) {
for (i = 1; i < argc; ++i) { int i;
if (*argv[i] == '\"' || *argv[i] == '\'') { for (i = 1; i < argc; ++i) {
strip_quotes(argv[i]); if (*argv[i] == '\"' || *argv[i] == '\'') {
strip_quotes(argv[i]);
}
} }
} }
struct cmd_handler *handler = find_handler(argv[0], CMD_BLOCK_END); struct cmd_handler *handler = find_handler(argv[0], CMD_BLOCK_END);