From 6840392df195992b8632353f7c5fb3a794c25f3f Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 20 May 2024 22:48:26 -0500 Subject: [PATCH] Stack longjmp return vectors so builtins calling builtins can xexit() back to the shell. --- tests/sh.test | 2 ++ toys/pending/sh.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/sh.test b/tests/sh.test index 306a4392..2322ed41 100644 --- a/tests/sh.test +++ b/tests/sh.test @@ -630,6 +630,8 @@ shxpect 'set -u' I$'set -u; echo $walrus\n' REwalrus X testing 'source file' 'source input' 'hello\n' 'echo hello \\\n' '' testing '. file' '. input' 'hello\n' 'echo hello \\\n' '' testing 'source no newline' 'source input' 'hello \\\n' 'echo hello \\' '' +testing 'source returns' 'echo hello; source <(echo false); echo $?' \ + 'hello\n1\n' '' '' testing 'source is live' \ 'for i in one two three; do echo "echo $i" > input; source input; done' \ 'one\ntwo\nthree\n' 'x' '' diff --git a/toys/pending/sh.c b/toys/pending/sh.c index 46390724..622b270c 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -2886,7 +2886,7 @@ static struct sh_process *run_command(void) // Is this command a builtin that should run in this process? if ((jj&TOYFLAG_NOFORK) || ((jj&TOYFLAG_MAYFORK) && !prefix)) { - sigjmp_buf rebound; + sigjmp_buf rebound, *prebound = toys.rebound; char temp[jj = offsetof(struct toy_context, rebound)]; // This fakes lots of what toybox_main() does. @@ -2904,7 +2904,7 @@ static struct sh_process *run_command(void) tl->toy_main(); xexit(); } - toys.rebound = 0; + toys.rebound = prebound; pp->exit = toys.exitval; clearerr(stdout); if (toys.optargs != toys.argv+1) free(toys.optargs); -- 2.39.2