From 00da72bee09cfe4a757cbba4465a76269dae9f43 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 23 Oct 2015 18:43:16 +0200 Subject: tidy up strtok use Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 8a1628e81..17121aa9b 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -2556,7 +2556,7 @@ updatepwd(const char *dir) new = stack_putstr(p, new); USTPUTC('/', new); } - p = strtok(0, "/"); + p = strtok(NULL, "/"); } if (new > lim) STUNPUTC(new); -- cgit v1.2.3-55-g6feb From 9121510dc659baf6664456796c195460468c850b Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 29 Oct 2015 11:29:59 +0000 Subject: ash: add test for issue with here document This used to work but doesn't now: foo () { cat < Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash_test/ash-heredoc/heredoc2.right | 2 ++ shell/ash_test/ash-heredoc/heredoc2.tests | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 shell/ash_test/ash-heredoc/heredoc2.right create mode 100755 shell/ash_test/ash-heredoc/heredoc2.tests (limited to 'shell') diff --git a/shell/ash_test/ash-heredoc/heredoc2.right b/shell/ash_test/ash-heredoc/heredoc2.right new file mode 100644 index 000000000..a486f1ac4 --- /dev/null +++ b/shell/ash_test/ash-heredoc/heredoc2.right @@ -0,0 +1,2 @@ +bar +bar diff --git a/shell/ash_test/ash-heredoc/heredoc2.tests b/shell/ash_test/ash-heredoc/heredoc2.tests new file mode 100755 index 000000000..6d9ccb6cc --- /dev/null +++ b/shell/ash_test/ash-heredoc/heredoc2.tests @@ -0,0 +1,7 @@ +foo () { +cat < Date: Mon, 3 Aug 2015 13:46:00 +0100 Subject: ash: allow newline after variable name in for loop Newline is a valid delimiter between the variable name and `in` keyword in for loops. Based on commit 22e8fb4 from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu. function old new delta parse_command 1568 1563 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5) Total: -5 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 4 ++-- shell/ash_test/ash-misc/for.right | 1 + shell/ash_test/ash-misc/for.tests | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 shell/ash_test/ash-misc/for.right create mode 100755 shell/ash_test/ash-misc/for.tests (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 17121aa9b..3339666b9 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10913,7 +10913,7 @@ parse_command(void) n1 = stzalloc(sizeof(struct nfor)); n1->type = NFOR; n1->nfor.var = wordtext; - checkkwd = CHKKWD | CHKALIAS; + checkkwd = CHKNL | CHKKWD | CHKALIAS; if (readtoken() == TIN) { app = ≈ while (readtoken() == TWORD) { @@ -10940,7 +10940,7 @@ parse_command(void) * Newline or semicolon here is optional (but note * that the original Bourne shell only allowed NL). */ - if (lasttoken != TNL && lasttoken != TSEMI) + if (lasttoken != TSEMI) tokpushback = 1; } checkkwd = CHKNL | CHKKWD | CHKALIAS; diff --git a/shell/ash_test/ash-misc/for.right b/shell/ash_test/ash-misc/for.right new file mode 100644 index 000000000..d86bac9de --- /dev/null +++ b/shell/ash_test/ash-misc/for.right @@ -0,0 +1 @@ +OK diff --git a/shell/ash_test/ash-misc/for.tests b/shell/ash_test/ash-misc/for.tests new file mode 100755 index 000000000..4889a9f2d --- /dev/null +++ b/shell/ash_test/ash-misc/for.tests @@ -0,0 +1,5 @@ +for i +in OK +do + echo $i +done -- cgit v1.2.3-55-g6feb From 383b885ff7654dc0171b5c1eaa449bb1e1cfe8f0 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 3 Aug 2015 13:46:25 +0100 Subject: ash: save a few bytes in code to parse case statements Based on commit 49b82fc from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu. function old new delta parse_command 1563 1555 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-8) Total: -8 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 3339666b9..18c7ff523 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10959,10 +10959,8 @@ parse_command(void) /*n2->narg.next = NULL; - stzalloc did it */ n2->narg.text = wordtext; n2->narg.backquote = backquotelist; - do { - checkkwd = CHKKWD | CHKALIAS; - } while (readtoken() == TNL); - if (lasttoken != TIN) + checkkwd = CHKNL | CHKKWD | CHKALIAS; + if (readtoken() != TIN) raise_error_unexpected_syntax(TIN); cpp = &n1->ncase.cases; next_case: -- cgit v1.2.3-55-g6feb From e2f32c02b149f5a128c634231a0ef12d03843967 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 29 Oct 2015 19:46:40 +0100 Subject: ash: fix command -- crash busybox sh -c 'command --' segfaults because parse_command_args returns a pointer to a null pointer. Based on commit 18071c7 from git://git.kernel.org/pub/scm/utils/dash/dash.git by Gerrit Pape. Signed-off-by: Denys Vlasenko --- shell/ash.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 18c7ff523..8f0a5e0be 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -8878,14 +8878,15 @@ parse_command_args(char **argv, const char **path) for (;;) { cp = *++argv; if (!cp) - return 0; + return NULL; if (*cp++ != '-') break; c = *cp++; if (!c) break; if (c == '-' && !*cp) { - argv++; + if (!*++argv) + return NULL; break; } do { @@ -8895,7 +8896,7 @@ parse_command_args(char **argv, const char **path) break; default: /* run 'typecmd' for other options */ - return 0; + return NULL; } c = *cp++; } while (c); -- cgit v1.2.3-55-g6feb From 3f221113a50196e536bfb059712915bd8bde10d1 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 3 Aug 2015 13:47:33 +0100 Subject: ash: respect -p flag when command builtin is run with -v/-V The command builtin should only check the default path, not $PATH, when the -p flag is used along with -v/-V. Based on commits 65ae84b (by Harald van Dijk) and 29ee27d (by Herbert Xu) from git://git.kernel.org/pub/scm/utils/dash/dash.git). function old new delta commandcmd 72 87 +15 describe_command 437 450 +13 typecmd 84 86 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 30/0) Total: 30 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 12 ++++++++---- shell/ash_test/ash-misc/command.right | 1 + shell/ash_test/ash-misc/command.tests | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 shell/ash_test/ash-misc/command.right create mode 100755 shell/ash_test/ash-misc/command.tests (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 8f0a5e0be..a2e06184b 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -7812,14 +7812,15 @@ findkwd(const char *s) * Locate and print what a word is... */ static int -describe_command(char *command, int describe_command_verbose) +describe_command(char *command, const char *path, int describe_command_verbose) { struct cmdentry entry; struct tblentry *cmdp; #if ENABLE_ASH_ALIAS const struct alias *ap; #endif - const char *path = pathval(); + + path = path ? path : pathval(); if (describe_command_verbose) { out1str(command); @@ -7919,7 +7920,7 @@ typecmd(int argc UNUSED_PARAM, char **argv) verbose = 0; } while (argv[i]) { - err |= describe_command(argv[i++], verbose); + err |= describe_command(argv[i++], NULL, verbose); } return err; } @@ -7933,6 +7934,7 @@ commandcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) VERIFY_BRIEF = 1, VERIFY_VERBOSE = 2, } verify = 0; + const char *path = NULL; while ((c = nextopt("pvV")) != '\0') if (c == 'V') @@ -7943,9 +7945,11 @@ commandcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) else if (c != 'p') abort(); #endif + else + path = bb_default_path; /* Mimic bash: just "command -v" doesn't complain, it's a nop */ if (verify && (*argptr != NULL)) { - return describe_command(*argptr, verify - VERIFY_BRIEF); + return describe_command(*argptr, path, verify - VERIFY_BRIEF); } return 0; diff --git a/shell/ash_test/ash-misc/command.right b/shell/ash_test/ash-misc/command.right new file mode 100644 index 000000000..7f746d9c4 --- /dev/null +++ b/shell/ash_test/ash-misc/command.right @@ -0,0 +1 @@ +recho: not found diff --git a/shell/ash_test/ash-misc/command.tests b/shell/ash_test/ash-misc/command.tests new file mode 100755 index 000000000..5d445af51 --- /dev/null +++ b/shell/ash_test/ash-misc/command.tests @@ -0,0 +1 @@ +command -p -V recho -- cgit v1.2.3-55-g6feb From ef2386b80abfb22ccb697ddbdd4047aacc395c50 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 29 Oct 2015 16:19:14 +0000 Subject: ash: only allow local variables in functions Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 3 +++ shell/ash_test/ash-misc/local2.right | 1 + shell/ash_test/ash-misc/local2.tests | 1 + 3 files changed, 5 insertions(+) create mode 100644 shell/ash_test/ash-misc/local2.right create mode 100755 shell/ash_test/ash-misc/local2.tests (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index a2e06184b..0d7cac0b5 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -8987,6 +8987,9 @@ localcmd(int argc UNUSED_PARAM, char **argv) { char *name; + if (!funcnest) + ash_msg_and_raise_error("not in a function"); + argv = argptr; while ((name = *argv++) != NULL) { mklocal(name); diff --git a/shell/ash_test/ash-misc/local2.right b/shell/ash_test/ash-misc/local2.right new file mode 100644 index 000000000..630ef7979 --- /dev/null +++ b/shell/ash_test/ash-misc/local2.right @@ -0,0 +1 @@ +./local2.tests: local: line 1: not in a function diff --git a/shell/ash_test/ash-misc/local2.tests b/shell/ash_test/ash-misc/local2.tests new file mode 100755 index 000000000..8e14037c5 --- /dev/null +++ b/shell/ash_test/ash-misc/local2.tests @@ -0,0 +1 @@ +local x=1 -- cgit v1.2.3-55-g6feb From 7b14ede049d467e1a6da46ef69b917645e94a6b9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 29 Oct 2015 20:29:05 +0100 Subject: ash tests: make test print test name before it is run Signed-off-by: Denys Vlasenko --- shell/ash_test/run-all | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'shell') diff --git a/shell/ash_test/run-all b/shell/ash_test/run-all index ad93e251d..354cc1fcf 100755 --- a/shell/ash_test/run-all +++ b/shell/ash_test/run-all @@ -31,8 +31,9 @@ do_test() *.orig|*~) ;; #*) echo $x ; sh $x ;; *) + echo -n "$1/$x: " sh "$x" >"$TOPDIR/$noslash-$x.fail" 2>&1 && \ - { echo "$1/$x: ok"; rm "$TOPDIR/$noslash-$x.fail"; } || echo "$1/$x: fail"; + { echo "ok"; rm "$TOPDIR/$noslash-$x.fail"; } || echo "fail"; ;; esac done @@ -42,11 +43,12 @@ do_test() test -x "$x" || continue name="${x%%.tests}" test -f "$name.right" || continue + echo -n "$1/$x: " { "$THIS_SH" "./$x" >"$name.xx" 2>&1 diff -u "$name.xx" "$name.right" >"$TOPDIR/$noslash-$x.fail" \ && rm -f "$name.xx" "$TOPDIR/$noslash-$x.fail" - } && echo "$1/$x: ok" || echo "$1/$x: fail" + } && echo "ok" || echo "fail" done ) } -- cgit v1.2.3-55-g6feb From 713f07d906d9171953be0c12e2369869855b6ca6 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 29 Oct 2015 16:44:56 +0000 Subject: ash: fix error during recursive processing of here document Save the value of the checkkwd flag to prevent it being clobbered during recursion. Based on commit ec2c84d from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu. function old new delta readtoken 190 203 +13 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0) Total: 13 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 5 +++-- shell/ash_test/ash-heredoc/heredoc3.right | 1 + shell/ash_test/ash-heredoc/heredoc3.tests | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 shell/ash_test/ash-heredoc/heredoc3.right create mode 100755 shell/ash_test/ash-heredoc/heredoc3.tests (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 0d7cac0b5..384c7b9e4 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -11899,6 +11899,7 @@ static int readtoken(void) { int t; + int kwd = checkkwd; #if DEBUG smallint alreadyseen = tokpushback; #endif @@ -11912,7 +11913,7 @@ readtoken(void) /* * eat newlines */ - if (checkkwd & CHKNL) { + if (kwd & CHKNL) { while (t == TNL) { parseheredoc(); t = xxreadtoken(); @@ -11926,7 +11927,7 @@ readtoken(void) /* * check for keywords */ - if (checkkwd & CHKKWD) { + if (kwd & CHKKWD) { const char *const *pp; pp = findkwd(wordtext); diff --git a/shell/ash_test/ash-heredoc/heredoc3.right b/shell/ash_test/ash-heredoc/heredoc3.right new file mode 100644 index 000000000..ce0136250 --- /dev/null +++ b/shell/ash_test/ash-heredoc/heredoc3.right @@ -0,0 +1 @@ +hello diff --git a/shell/ash_test/ash-heredoc/heredoc3.tests b/shell/ash_test/ash-heredoc/heredoc3.tests new file mode 100755 index 000000000..96c227cc1 --- /dev/null +++ b/shell/ash_test/ash-heredoc/heredoc3.tests @@ -0,0 +1,9 @@ +echo hello >greeting +cat </dev/null +rm greeting -- cgit v1.2.3-55-g6feb From 6bd2fabc52fa76b69a65772878e2e745c0fff3ff Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 29 Oct 2015 11:30:22 +0000 Subject: Revert "ash: fix a SEGV case in an invalid heredoc" xxx This reverts commit 7e66102f762a7d80715f0c7e5925433256b78cee but leaves the test in place as it's still valid. Reported-by: Natanael Copa Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 384c7b9e4..72fc7d524 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10524,7 +10524,7 @@ static union node *andor(void); static union node *pipeline(void); static union node *parse_command(void); static void parseheredoc(void); -static char nexttoken_ends_list(void); +static char peektoken(void); static int readtoken(void); static union node * @@ -10534,7 +10534,7 @@ list(int nlflag) int tok; checkkwd = CHKNL | CHKKWD | CHKALIAS; - if (nlflag == 2 && nexttoken_ends_list()) + if (nlflag == 2 && peektoken()) return NULL; n1 = NULL; for (;;) { @@ -10576,15 +10576,8 @@ list(int nlflag) tokpushback = 1; } checkkwd = CHKNL | CHKKWD | CHKALIAS; - if (nexttoken_ends_list()) { - /* Testcase: "< Date: Thu, 29 Oct 2015 11:30:55 +0000 Subject: ash: simplify EOF/newline handling in list parser Processing of here documents in ash has had a couple of breakages which are now the subject of tests. This commit should fix both. It is based on the following commit in dash git by Herbert Xu: <7c245aa> [PARSER] Simplify EOF/newline handling in list parser (See git://git.kernel.org/pub/scm/utils/dash/dash.git) Reported-by: Natanael Copa Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 63 ++++++++++++++++++++++++++++--------------------------------- 1 file changed, 29 insertions(+), 34 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 72fc7d524..9a8bab5ab 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10524,7 +10524,7 @@ static union node *andor(void); static union node *pipeline(void); static union node *parse_command(void); static void parseheredoc(void); -static char peektoken(void); +static int peektoken(void); static int readtoken(void); static union node * @@ -10533,11 +10533,27 @@ list(int nlflag) union node *n1, *n2, *n3; int tok; - checkkwd = CHKNL | CHKKWD | CHKALIAS; - if (nlflag == 2 && peektoken()) - return NULL; n1 = NULL; for (;;) { + switch (peektoken()) { + case TNL: + if (!(nlflag & 1)) + break; + parseheredoc(); + return n1; + + case TEOF: + if (!n1 && (nlflag & 1)) + n1 = NODE_EOF; + parseheredoc(); + return n1; + } + + checkkwd = CHKNL | CHKKWD | CHKALIAS; + if (nlflag == 2 && tokname_array[peektoken()][0]) + return n1; + nlflag |= 2; + n2 = andor(); tok = readtoken(); if (tok == TBACKGND) { @@ -10563,30 +10579,15 @@ list(int nlflag) n1 = n3; } switch (tok) { + case TNL: + case TEOF: + tokpushback = 1; + /* fall through */ case TBACKGND: case TSEMI: - tok = readtoken(); - /* fall through */ - case TNL: - if (tok == TNL) { - parseheredoc(); - if (nlflag == 1) - return n1; - } else { - tokpushback = 1; - } - checkkwd = CHKNL | CHKKWD | CHKALIAS; - if (peektoken()) - return n1; break; - case TEOF: - if (heredoclist) - parseheredoc(); - else - pungetc(); /* push back EOF on input */ - return n1; default: - if (nlflag == 1) + if ((nlflag & 1)) raise_error_unexpected_syntax(-1); tokpushback = 1; return n1; @@ -11954,14 +11955,14 @@ readtoken(void) return t; } -static char +static int peektoken(void) { int t; t = readtoken(); tokpushback = 1; - return tokname_array[t][0]; + return t; } /* @@ -11971,18 +11972,12 @@ peektoken(void) static union node * parsecmd(int interact) { - int t; - tokpushback = 0; + checkkwd = 0; + heredoclist = 0; doprompt = interact; setprompt_if(doprompt, doprompt); needprompt = 0; - t = readtoken(); - if (t == TEOF) - return NODE_EOF; - if (t == TNL) - return NULL; - tokpushback = 1; return list(1); } -- cgit v1.2.3-55-g6feb From 112889d70670a23ecf8d493eab7e632b47435bb9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 29 Oct 2015 22:37:25 +0100 Subject: hush: copy for.tests from ash testsuite This test passes for hush Signed-off-by: Denys Vlasenko --- shell/hush_test/hush-misc/for.right | 1 + shell/hush_test/hush-misc/for.tests | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 shell/hush_test/hush-misc/for.right create mode 100755 shell/hush_test/hush-misc/for.tests (limited to 'shell') diff --git a/shell/hush_test/hush-misc/for.right b/shell/hush_test/hush-misc/for.right new file mode 100644 index 000000000..d86bac9de --- /dev/null +++ b/shell/hush_test/hush-misc/for.right @@ -0,0 +1 @@ +OK diff --git a/shell/hush_test/hush-misc/for.tests b/shell/hush_test/hush-misc/for.tests new file mode 100755 index 000000000..4889a9f2d --- /dev/null +++ b/shell/hush_test/hush-misc/for.tests @@ -0,0 +1,5 @@ +for i +in OK +do + echo $i +done -- cgit v1.2.3-55-g6feb From e939856c8724e357b3a7ba878563bfc957605504 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 30 Oct 2015 19:05:55 +0000 Subject: ash: add tests for failures of the exec and command builtins The exec builtin should return an exit status of 127 if the command can't be found. It doesn't: it returns 2. If the command builtin is used to source a script that runs a second script that doesn't exist ash should issue an error. Instead it seg faults. Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash_test/ash-misc/command2.right | 2 ++ shell/ash_test/ash-misc/command2.tests | 6 ++++++ shell/ash_test/ash-misc/exec.right | 2 ++ shell/ash_test/ash-misc/exec.tests | 3 +++ 4 files changed, 13 insertions(+) create mode 100644 shell/ash_test/ash-misc/command2.right create mode 100755 shell/ash_test/ash-misc/command2.tests create mode 100644 shell/ash_test/ash-misc/exec.right create mode 100755 shell/ash_test/ash-misc/exec.tests (limited to 'shell') diff --git a/shell/ash_test/ash-misc/command2.right b/shell/ash_test/ash-misc/command2.right new file mode 100644 index 000000000..8d2165f69 --- /dev/null +++ b/shell/ash_test/ash-misc/command2.right @@ -0,0 +1,2 @@ +test1 +./command2.tests: ./test1.sh: line 1: ./test2.sh: Permission denied diff --git a/shell/ash_test/ash-misc/command2.tests b/shell/ash_test/ash-misc/command2.tests new file mode 100755 index 000000000..9d9de9a89 --- /dev/null +++ b/shell/ash_test/ash-misc/command2.tests @@ -0,0 +1,6 @@ +echo "echo test1; ./test2.sh" >test1.sh +echo "echo test2" >test2.sh + +command . ./test1.sh + +rm -f test1.sh test2.sh diff --git a/shell/ash_test/ash-misc/exec.right b/shell/ash_test/ash-misc/exec.right new file mode 100644 index 000000000..1741a38dd --- /dev/null +++ b/shell/ash_test/ash-misc/exec.right @@ -0,0 +1,2 @@ +./exec.tests: exec: line 2: ./test1.sh: not found +127 diff --git a/shell/ash_test/ash-misc/exec.tests b/shell/ash_test/ash-misc/exec.tests new file mode 100755 index 000000000..624915de1 --- /dev/null +++ b/shell/ash_test/ash-misc/exec.tests @@ -0,0 +1,3 @@ +rm -f test1.sh +(exec ./test1.sh) +echo $? -- cgit v1.2.3-55-g6feb From 8c55dc79a79d6a16c364e6b1f849bf426f21fcbb Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 30 Oct 2015 19:06:47 +0000 Subject: ash: fix EXEXEC status clobbering evalcommand always clobbers the exit status in case of an EXEXEC which means that exec always fails with exit status 2 regardless of what it actually returns. This patch adds the missing check for EXEXEC so that the correct exit status is preserved. It causes the test ash-misc/exec.tests to succeed. Based on commit 7f68426 in dash git, by Herbert Xu. Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 9a8bab5ab..c333b235b 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -9432,7 +9432,7 @@ evalcommand(union node *cmd, int flags) if (evalbltin(cmdentry.u.cmd, argc, argv)) { int exit_status; int i = exception_type; - if (i == EXEXIT) + if (i == EXEXIT || i == EXEXEC) goto raise; exit_status = 2; if (i == EXINT) -- cgit v1.2.3-55-g6feb From 95650a86d176ee83a264fd9e7047c414b71ee7cb Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 30 Oct 2015 19:07:37 +0000 Subject: ash: allow popredir to be called if the stack is empty If /tmp/test.sh is a script that tries to run a second script which happens to be non-executable this: command . /tmp/test.sh causes a seg fault. This is because clearredir is called in the error path to clear the stack of redirections. The normal path then calls popredir, but popredir fails when the stack is empty. Reported-by: Bastian Bittorf Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index c333b235b..84502636a 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -5409,7 +5409,7 @@ popredir(int drop, int restore) struct redirtab *rp; int i; - if (--g_nullredirs >= 0) + if (--g_nullredirs >= 0 || redirlist == NULL) return; INT_OFF; rp = redirlist; -- cgit v1.2.3-55-g6feb