From 46d5a7fcea81b489819f753451c1ad2fe435f148 Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Tue, 27 Mar 2018 00:39:35 +0800 Subject: 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 Signed-off-by: Herbert Xu --- src/eval.c | 3 +++ src/input.c | 10 ++++++++-- src/input.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/eval.c b/src/eval.c index 19e06ec..4b67fc9 100644 --- a/src/eval.c +++ b/src/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/src/input.c b/src/input.c index e53423c..ae0c4c8 100644 --- a/src/input.c +++ b/src/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/src/input.h b/src/input.h index ec97c1d..a9c0517 100644 --- a/src/input.h +++ b/src/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); -- cgit 1.4.1 1.9&id=c0ee457ab146326a961008e518b7ffbc581ec744&follow=1'>root/irc.c (unfollow)
Commit message (Expand)Author
2018-08-08Use BLACK LEFT-POINTING TRIANGLE for markerJune McEnroe
2018-08-07Reset attrs after addIRCJune McEnroe
2018-08-07Add tab complete UIJune McEnroe
2018-08-07Implement cycling tab completeJune McEnroe
2018-08-07Mark log when scrolling upJune McEnroe
2018-08-07Remove extraneous slash from unrecognized commandJune McEnroe
2018-08-07Highlight and beep pingsJune McEnroe
2018-08-07Factor out allocating conversion between wcs and mbsJune McEnroe
2018-08-07Match commands case-insensitivelyJune McEnroe
2018-08-07Convert input to multibyte before handlingJune McEnroe
2018-08-07Populate tab-complete listJune McEnroe
2018-08-07Fix /me formatting side-effectsJune McEnroe
2018-08-07Define ui.c BUF_LEN with enumJune McEnroe
2018-08-07Hack clang into checking uiFmt format stringsJune McEnroe
2018-08-07Handle PART and QUIT without messagesJune McEnroe
2018-08-07Make safe filling the who bufferJune McEnroe
2018-08-07Add reverse and reset IRC formatting codesJune McEnroe
2018-08-06Rewrite line editing again, add formattingJune McEnroe
2018-08-06Fix allocation size in vaswprintfJune McEnroe
2018-08-06Implement word wrappingJune McEnroe
2018-08-06Use wchar_t strings for all of UIJune McEnroe
2018-08-06Rename line editing functionsJune McEnroe
2018-08-05Initialize all possible color pairsJune McEnroe
2018-08-05Refactor color initializationJune McEnroe
2018-08-05Add ^L redrawJune McEnroe
2018-08-05Use 16 colors if availableJune McEnroe
2018-08-05Limit parsed colors to number of mIRC colorsJune McEnroe
2018-08-04Show source link on exitJune McEnroe
2018-08-04Implement line editing, scrollingJune McEnroe
2018-08-04Handle /topicJune McEnroe