[klibc] [klibc:update-dash] eval: Restore input files in evalcommand
klibc-bot for Herbert Xu
herbert at gondor.apana.org.au
Thu Jan 24 19:15:59 PST 2019
Commit-ID: 2b231302b19d9213263d001b0c467e28ecc033f3
Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=2b231302b19d9213263d001b0c467e28ecc033f3
Author: Herbert Xu <herbert at gondor.apana.org.au>
AuthorDate: Tue, 27 Mar 2018 00:39:35 +0800
Committer: Ben Hutchings <ben at decadent.org.uk>
CommitDate: Fri, 25 Jan 2019 02:57:21 +0000
[klibc] 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 at inlv.org>
Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>
---
usr/dash/eval.c | 3 +++
usr/dash/input.c | 10 ++++++++--
usr/dash/input.h | 1 +
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/usr/dash/eval.c b/usr/dash/eval.c
index 811c28a4..5fd1c7c1 100644
--- a/usr/dash/eval.c
+++ b/usr/dash/eval.c
@@ -694,6 +694,7 @@ evalcommand(union node *cmd, int flags)
#endif
{
struct localvar_list *localvar_stop;
+ struct parsefile *file_stop;
struct redirtab *redir_stop;
struct stackmark smark;
union node *argp;
@@ -722,6 +723,7 @@ evalcommand(union node *cmd, int flags)
TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags));
setstackmark(&smark);
localvar_stop = pushlocalvars();
+ file_stop = parsefile;
back_exitstatus = 0;
cmdentry.cmdtype = CMDBUILTIN;
@@ -896,6 +898,7 @@ out:
if (cmd->ncmd.redirect)
popredir(execcmd);
unwindredir(redir_stop);
+ unwindfiles(file_stop);
unwindlocalvars(localvar_stop);
if (lastarg)
/* dsl: I think this is intended to be used to support
diff --git a/usr/dash/input.c b/usr/dash/input.c
index e53423c5..ae0c4c80 100644
--- a/usr/dash/input.c
+++ b/usr/dash/input.c
@@ -479,6 +479,13 @@ popfile(void)
}
+void unwindfiles(struct parsefile *stop)
+{
+ while (parsefile != stop)
+ popfile();
+}
+
+
/*
* Return to top level.
*/
@@ -486,8 +493,7 @@ popfile(void)
void
popallfiles(void)
{
- while (parsefile != &basepf)
- popfile();
+ unwindfiles(&basepf);
}
diff --git a/usr/dash/input.h b/usr/dash/input.h
index ec97c1d6..a9c05174 100644
--- a/usr/dash/input.h
+++ b/usr/dash/input.h
@@ -97,5 +97,6 @@ void popstring(void);
int setinputfile(const char *, int);
void setinputstring(char *);
void popfile(void);
+void unwindfiles(struct parsefile *);
void popallfiles(void);
void closescript(void);
More information about the klibc
mailing list