diff options
Diffstat (limited to 'run-command.c')
-rw-r--r-- | run-command.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/run-command.c b/run-command.c index b2bdcfda3d..47ced570bd 100644 --- a/run-command.c +++ b/run-command.c @@ -28,15 +28,17 @@ static const char **prepare_shell_cmd(const char **argv) if (argc < 1) die("BUG: shell command is empty"); - nargv[nargc++] = "sh"; - nargv[nargc++] = "-c"; - - if (argc < 2) - nargv[nargc++] = argv[0]; - else { - struct strbuf arg0 = STRBUF_INIT; - strbuf_addf(&arg0, "%s \"$@\"", argv[0]); - nargv[nargc++] = strbuf_detach(&arg0, NULL); + if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) { + nargv[nargc++] = "sh"; + nargv[nargc++] = "-c"; + + if (argc < 2) + nargv[nargc++] = argv[0]; + else { + struct strbuf arg0 = STRBUF_INIT; + strbuf_addf(&arg0, "%s \"$@\"", argv[0]); + nargv[nargc++] = strbuf_detach(&arg0, NULL); + } } for (argc = 0; argv[argc]; argc++) |