aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-08-05 17:07:26 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-08-05 18:11:15 +0200
commit1c5eb88cd84c90e4c3d014f4abc8f8310c008842 (patch)
tree50cff50b137d834599d2e9690ebf4802c5a87cf1
parent58eb805c2c453c6764acbd65f5604465438d9272 (diff)
downloadbusybox-w32-1c5eb88cd84c90e4c3d014f4abc8f8310c008842.tar.gz
busybox-w32-1c5eb88cd84c90e4c3d014f4abc8f8310c008842.tar.bz2
busybox-w32-1c5eb88cd84c90e4c3d014f4abc8f8310c008842.zip
ash: eval: Restore input files in evalcommand
Upstream commit: Date: Tue, 27 Mar 2018 00:39:35 +0800 eval: Restore input files in evalcommand When evalcommand invokes a command that modifies parsefile and then bails out without popping the file, we need to ensure the input file is restored so that the shell can continue to execute. Reported-by: Martijn Dekker <martijn@inlv.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta unwindfiles - 20 +20 evalcommand 1635 1653 +18 getoptscmd 584 595 +11 popallfiles 20 10 -10 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/1 up/down: 49/-10) Total: 39 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/shell/ash.c b/shell/ash.c
index b596833e7..79ade5df4 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -9942,6 +9942,7 @@ find_builtin(const char *name)
9942/* 9942/*
9943 * Execute a simple command. 9943 * Execute a simple command.
9944 */ 9944 */
9945static void unwindfiles(struct parsefile *stop);
9945static int 9946static int
9946isassignment(const char *p) 9947isassignment(const char *p)
9947{ 9948{
@@ -9964,6 +9965,7 @@ evalcommand(union node *cmd, int flags)
9964 "\0\0", bltincmd /* why three NULs? */ 9965 "\0\0", bltincmd /* why three NULs? */
9965 }; 9966 };
9966 struct localvar_list *localvar_stop; 9967 struct localvar_list *localvar_stop;
9968 struct parsefile *file_stop;
9967 struct redirtab *redir_stop; 9969 struct redirtab *redir_stop;
9968 struct stackmark smark; 9970 struct stackmark smark;
9969 union node *argp; 9971 union node *argp;
@@ -9989,6 +9991,7 @@ evalcommand(union node *cmd, int flags)
9989 TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); 9991 TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags));
9990 setstackmark(&smark); 9992 setstackmark(&smark);
9991 localvar_stop = pushlocalvars(); 9993 localvar_stop = pushlocalvars();
9994 file_stop = g_parsefile;
9992 back_exitstatus = 0; 9995 back_exitstatus = 0;
9993 9996
9994 cmdentry.cmdtype = CMDBUILTIN; 9997 cmdentry.cmdtype = CMDBUILTIN;
@@ -10260,6 +10263,7 @@ evalcommand(union node *cmd, int flags)
10260 if (cmd->ncmd.redirect) 10263 if (cmd->ncmd.redirect)
10261 popredir(/*drop:*/ cmd_is_exec); 10264 popredir(/*drop:*/ cmd_is_exec);
10262 unwindredir(redir_stop); 10265 unwindredir(redir_stop);
10266 unwindfiles(file_stop);
10263 unwindlocalvars(localvar_stop); 10267 unwindlocalvars(localvar_stop);
10264 if (lastarg) { 10268 if (lastarg) {
10265 /* dsl: I think this is intended to be used to support 10269 /* dsl: I think this is intended to be used to support
@@ -10782,14 +10786,20 @@ popfile(void)
10782 INT_ON; 10786 INT_ON;
10783} 10787}
10784 10788
10789static void
10790unwindfiles(struct parsefile *stop)
10791{
10792 while (g_parsefile != stop)
10793 popfile();
10794}
10795
10785/* 10796/*
10786 * Return to top level. 10797 * Return to top level.
10787 */ 10798 */
10788static void 10799static void
10789popallfiles(void) 10800popallfiles(void)
10790{ 10801{
10791 while (g_parsefile != &basepf) 10802 unwindfiles(&basepf);
10792 popfile();
10793} 10803}
10794 10804
10795/* 10805/*