diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-02-19 15:30:20 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-02-20 09:36:51 +0100 |
| commit | 54bef2a8efd21e9992a9d26cf30c5b26cbc0e21a (patch) | |
| tree | d7b25fc37724cbd4fe0820663648a45ed77c9565 /shell | |
| parent | 7eb8eecbbc752d04381f35d196bbdf1e3b17e2d1 (diff) | |
| download | busybox-w32-54bef2a8efd21e9992a9d26cf30c5b26cbc0e21a.tar.gz busybox-w32-54bef2a8efd21e9992a9d26cf30c5b26cbc0e21a.tar.bz2 busybox-w32-54bef2a8efd21e9992a9d26cf30c5b26cbc0e21a.zip | |
ash: eval: Fail immediately with redirections errors for simple command
Upstream commit:
Date: Sat, 19 May 2018 02:39:54 +0800
eval: Fail immediately with redirections errors for simple command
Previously, dash would continue to perform variable expansions
even if a redirection error occured. This patch changes it so
that it fails immediately.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/ash.c | 32 | ||||
| -rw-r--r-- | shell/ash_test/ash-redir/redir_exec1.right | 1 |
2 files changed, 16 insertions, 17 deletions
diff --git a/shell/ash.c b/shell/ash.c index 145896229..5570057e9 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -10253,6 +10253,17 @@ evalcommand(union node *cmd, int flags) | |||
| 10253 | } | 10253 | } |
| 10254 | status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH | REDIR_SAVEFD2); | 10254 | status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH | REDIR_SAVEFD2); |
| 10255 | 10255 | ||
| 10256 | if (status) { | ||
| 10257 | bail: | ||
| 10258 | exitstatus = status; | ||
| 10259 | |||
| 10260 | /* We have a redirection error. */ | ||
| 10261 | if (spclbltin > 0) | ||
| 10262 | raise_exception(EXERROR); | ||
| 10263 | |||
| 10264 | goto out; | ||
| 10265 | } | ||
| 10266 | |||
| 10256 | for (argp = cmd->ncmd.assign; argp; argp = argp->narg.next) { | 10267 | for (argp = cmd->ncmd.assign; argp; argp = argp->narg.next) { |
| 10257 | struct strlist **spp; | 10268 | struct strlist **spp; |
| 10258 | 10269 | ||
| @@ -10304,28 +10315,17 @@ evalcommand(union node *cmd, int flags) | |||
| 10304 | ) { | 10315 | ) { |
| 10305 | find_command(argv[0], &cmdentry, cmd_flag | DO_ERR, | 10316 | find_command(argv[0], &cmdentry, cmd_flag | DO_ERR, |
| 10306 | path ? path : pathval()); | 10317 | path ? path : pathval()); |
| 10307 | if (cmdentry.cmdtype == CMDUNKNOWN) { | ||
| 10308 | status = 127; | ||
| 10309 | flush_stdout_stderr(); | ||
| 10310 | goto bail; | ||
| 10311 | } | ||
| 10312 | } | ||
| 10313 | |||
| 10314 | if (status) { | ||
| 10315 | bail: | ||
| 10316 | exitstatus = status; | ||
| 10317 | |||
| 10318 | /* We have a redirection error. */ | ||
| 10319 | if (spclbltin > 0) | ||
| 10320 | raise_exception(EXERROR); | ||
| 10321 | |||
| 10322 | goto out; | ||
| 10323 | } | 10318 | } |
| 10324 | 10319 | ||
| 10325 | jp = NULL; | 10320 | jp = NULL; |
| 10326 | 10321 | ||
| 10327 | /* Execute the command. */ | 10322 | /* Execute the command. */ |
| 10328 | switch (cmdentry.cmdtype) { | 10323 | switch (cmdentry.cmdtype) { |
| 10324 | case CMDUNKNOWN: | ||
| 10325 | status = 127; | ||
| 10326 | flush_stdout_stderr(); | ||
| 10327 | goto bail; | ||
| 10328 | |||
| 10329 | default: { | 10329 | default: { |
| 10330 | 10330 | ||
| 10331 | #if ENABLE_FEATURE_SH_STANDALONE \ | 10331 | #if ENABLE_FEATURE_SH_STANDALONE \ |
diff --git a/shell/ash_test/ash-redir/redir_exec1.right b/shell/ash_test/ash-redir/redir_exec1.right index c98455bf5..26a664edc 100644 --- a/shell/ash_test/ash-redir/redir_exec1.right +++ b/shell/ash_test/ash-redir/redir_exec1.right | |||
| @@ -1,2 +1 @@ | |||
| 1 | ./redir_exec1.tests: line 1: can't create /cant/be/created: nonexistent directory | ./redir_exec1.tests: line 1: can't create /cant/be/created: nonexistent directory | |
| 2 | First | ||
