diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-28 21:58:27 -0600 |
|---|---|---|
| committer | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-28 21:58:27 -0600 |
| commit | eb8f9331cd2f0c240ba1323ef136b31611215f29 (patch) | |
| tree | fd242d98a3933fdb991d714c560b7274536ddbcd /src/parser.c | |
| parent | b97207f7e5dd3d8d147da525ede1ba3609f5c983 (diff) | |
| download | zash-eb8f9331cd2f0c240ba1323ef136b31611215f29.tar.gz | |
Fix redirection, parser, arithmetic, environment, and exec bugs
- Fail cleanly in save_fd() when sys_dupfd() fails with errno != EBADF,
check moved < 0 in plan_redirs()/plan_apply(), and reject duplicating
from closed descriptors in plan_redirs().
- Accept uppercase digits in parse_based() for bases <= 36 while keeping
ksh case-sensitive digits for bases 37..64.
- Save and restore in_cond, alias_ended_blank, and here_head/here_tail in
parse_cmdsub() and parse_substring(); parse inner double quotes inside
"${x:-...}" via read_double_quoted(); reject 'for x; in ...'.
- Deduplicate repeated temporary assignments in var_environ_with().
- Use access(X_OK) in path_search(), expand PS4 in xtrace() with recursion
guarded, report stdout write errors in run_pure()/eval_subshell(), and
restore loop/dot/func depth and skip_kind on eval_pipe() error unwind.
Verified locally on Linux (make, make zos-lint, make check: 128/129 pass).
Diffstat (limited to 'src/parser.c')
| -rw-r--r-- | src/parser.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/parser.c b/src/parser.c index 98d4c0b..aa3b9d4 100644 --- a/src/parser.c +++ b/src/parser.c @@ -414,12 +414,24 @@ static void parse_braced_param(pbuild *b, bool q, bool dq) { static node *parse_cmdsub(void) { token saved = tok; bool saved_pushed = tok_pushed; + bool saved_cond = in_cond; + bool saved_alias = alias_ended_blank; + heredoc *saved_head = here_head; + heredoc **saved_tail = here_tail == &here_head ? nullptr : here_tail; tok_pushed = false; + in_cond = false; + alias_ended_blank = false; + here_head = nullptr; + here_tail = &here_head; node *n = parse_clist(); if (tok.t != T_RP || !tok_pushed) syntax_error("missing ')'"); tok = saved; tok_pushed = saved_pushed; + in_cond = saved_cond; + alias_ended_blank = saved_alias; + here_head = saved_head; + here_tail = saved_tail ? saved_tail : &here_head; return n; } @@ -730,8 +742,6 @@ static void read_parts(pbuild *b, lex_mode mode, bool litq) { return; if (mode == M_HERE || mode == M_ARITH) break; - if (mode == M_BRACE_DQ && !pattern) - continue; /* "${x:-"y"}": the inner quotes are redundant */ read_double_quoted(b); continue; case '$': @@ -1403,10 +1413,13 @@ static node *parse_for(bool menu) { if (tok.t != T_WORD || !tok.word->plain || !is_name(tok.word->plain)) syntax_error("bad for loop variable"); n->u.for_.var = tok.word->plain; - if (peek() == T_SEMI) + bool had_semi = false; + if (peek() == T_SEMI) { + had_semi = true; consume(); + } skip_newlines(); - if (accept_kw(KW_IN)) { + if (!had_semi && accept_kw(KW_IN)) { n->u.for_.has_in = true; word **tail = &n->u.for_.words; while (peek() == T_WORD) { @@ -2089,7 +2102,15 @@ node *parse_command(arena *a, bool *eof) { static node *parse_substring(const char *s, size_t len) { token saved = tok; bool saved_pushed = tok_pushed; + bool saved_cond = in_cond; + bool saved_alias = alias_ended_blank; + heredoc *saved_head = here_head; + heredoc **saved_tail = here_tail == &here_head ? nullptr : here_tail; tok_pushed = false; + in_cond = false; + alias_ended_blank = false; + here_head = nullptr; + here_tail = &here_head; input_push_string(s, len); node *n = parse_clist(); if (peek() != T_EOF) @@ -2097,6 +2118,10 @@ static node *parse_substring(const char *s, size_t len) { input_pop(); tok = saved; tok_pushed = saved_pushed; + in_cond = saved_cond; + alias_ended_blank = saved_alias; + here_head = saved_head; + here_tail = saved_tail ? saved_tail : &here_head; return n; } @@ -2152,8 +2177,8 @@ static_assert(sizeof(parser_state) <= PARSER_STATE_SIZE, */ void parser_save(void *state) { parser_state *ps = state; - *ps = (parser_state){pa, tok, tok_pushed, here_head, here_tail, in_cond, - alias_ended_blank}; + *ps = (parser_state){pa, tok, tok_pushed, here_head, + here_tail, in_cond, alias_ended_blank}; if (here_tail == &here_head) ps->here_tail = nullptr; parser_reset(); |
