From fcad1d1e84c3b56b440b2d04e17ad243f41975d0 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 1 Feb 2021 15:09:07 -0500 Subject: [PATCH] commit bash-20210127 snapshot --- CWRU/CWRU.chlog | 12 ++++++++++++ MANIFEST | 1 + array.c | 3 --- array.h | 3 +-- doc/bashref.texi | 5 ++++- execute_cmd.c | 33 +++++++++++++++++---------------- tests/errors.right | 6 ++---- tests/extglob.right | 10 ++++++++++ tests/extglob.tests | 2 ++ tests/extglob6.sub | 41 +++++++++++++++++++++++++++++++++++++++++ 10 files changed, 90 insertions(+), 26 deletions(-) create mode 100644 tests/extglob6.sub diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 145d6541..b5868a07 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -9450,3 +9450,15 @@ lib/glob/glob.c subpattern to be cut off when calling skipname - extglob_skipname,wextglob_skipname: some cleanups so the code is closer to identical for the single-byte and wide character versions + + 2/1 + --- +execute_cmd.c + - execute_simple_command: in posix mode, if we have a variable + assignment error while assigning into the temporary environment (e.g., + assigning to a readonly variable), a non-interactive shell running a + special builtin exits; a non-interactive shell running anything else + jumps back to the top level. A shell compiled with -DSTRICT_POSIX + exits unconditionally. + - execute_simple_command: make sure posix mode sets $? to non-zero + if a variable assignment error occurs preceding a non-special builtin diff --git a/MANIFEST b/MANIFEST index 9a12cc9f..c808448d 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1092,6 +1092,7 @@ tests/extglob3.tests f tests/extglob3.right f tests/extglob4.sub f tests/extglob5.sub f +tests/extglob6.sub f tests/func.tests f tests/func.right f tests/func1.sub f diff --git a/array.c b/array.c index 6d3554bf..2521ce1a 100644 --- a/array.c +++ b/array.c @@ -84,7 +84,6 @@ array_create() ARRAY_ELEMENT *head; r = (ARRAY *)xmalloc(sizeof(ARRAY)); - r->type = array_indexed; r->max_index = -1; r->num_elements = 0; r->lastref = (ARRAY_ELEMENT *)0; @@ -134,7 +133,6 @@ ARRAY *a; if (a == 0) return((ARRAY *) NULL); a1 = array_create(); - a1->type = a->type; a1->max_index = a->max_index; a1->num_elements = a->num_elements; for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae)) { @@ -161,7 +159,6 @@ ARRAY_ELEMENT *s, *e; arrayind_t mi; a = array_create (); - a->type = array->type; for (mi = 0, p = s, i = 0; p != e; p = element_forw(p), i++) { n = array_create_element (element_index(p), element_value(p)); diff --git a/array.h b/array.h index 189d646f..a5e01e27 100644 --- a/array.h +++ b/array.h @@ -27,10 +27,9 @@ typedef intmax_t arrayind_t; -enum atype {array_indexed, array_assoc}; /* only array_indexed used */ +enum atype {array_indexed, array_assoc}; /* not used */ typedef struct array { - enum atype type; arrayind_t max_index; int num_elements; struct array_element *head; diff --git a/doc/bashref.texi b/doc/bashref.texi index ed42ed8a..9aecfac4 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -7819,7 +7819,10 @@ a value to a readonly variable. @item A non-interactive shell exits with an error status if a variable assignment error occurs in an assignment statement preceding a special -builtin, but not with any other simple command. +builtin, but not with any other simple command. For any other simple +command, the shell aborts execution of that command, and execution continues +at the top level ("the shell shall not perform any further processing of the +command in which the error occurred"). @item A non-interactive shell exits with an error status if the iteration diff --git a/execute_cmd.c b/execute_cmd.c index 319a70e7..e298ff4a 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -3013,16 +3013,13 @@ eval_arith_for_expr (l, okp) int r; char *expr, *temp; -#if 1 /* TAG: bash-5.2 */ expr = l->next ? string_list (l) : l->word->word; temp = expand_arith_string (expr, Q_DOUBLE_QUOTES|Q_ARITH); if (l->next) free (expr); new = make_word_list (make_word (temp), (WORD_LIST *)NULL); free (temp); -#else - new = expand_words_no_vars (l); -#endif + if (new) { if (echo_command_at_execute) @@ -3791,10 +3788,7 @@ execute_arith_command (arith_command) t = (char *)NULL; new = arith_command->exp; - if (new->next) - exp = t = string_list (new); /* just in case */ - else - exp = new->word->word; + exp = (new->next) ? (t = string_list (new)) : new->word->word; exp = expand_arith_string (exp, Q_DOUBLE_QUOTES|Q_ARITH); FREE (t); @@ -4459,16 +4453,23 @@ execute_simple_command (simple_command, pipe_in, pipe_out, async, fds_to_close) } /* In POSIX mode, assignment errors in the temporary environment cause a - non-interactive shell to exit. */ -#if 1 - if (posixly_correct && builtin_is_special && interactive_shell == 0 && tempenv_assign_error) -#else - /* This is for strict posix conformance. */ - if (posixly_correct && interactive_shell == 0 && tempenv_assign_error) -#endif + non-interactive shell executing a special builtin to exit and a non- + interactive shell to otherwise jump back to the top level. This is what + POSIX says to do for variable assignment errors, and errors in assigning + to the temporary environment are treated as variable assignment errors. */ + if (posixly_correct && tempenv_assign_error) { last_command_exit_value = EXECUTION_FAILURE; - jump_to_top_level (ERREXIT); +#if defined (STRICT_POSIX) + jump_to_top_level ((interactive_shell == 0) ? ERREXIT : DISCARD); +#else + if (interactive_shell == 0 && builtin_is_special) + jump_to_top_level (ERREXIT); + else if (interactive_shell == 0) + jump_to_top_level (DISCARD); + else + jump_to_top_level (DISCARD); +#endif } tempenv_assign_error = 0; /* don't care about this any more */ diff --git a/tests/errors.right b/tests/errors.right index 0bfe7418..9d0e2c0d 100644 --- a/tests/errors.right +++ b/tests/errors.right @@ -177,11 +177,9 @@ after non-special builtin: 0 after special builtin: 0 ./errors7.sub: line 27: x: readonly variable ./errors7.sub: line 21: x: readonly variable -./errors7.sub: line 21: notthere: command not found -after no such command: 127 +after no such command: 1 ./errors7.sub: line 23: x: readonly variable -echo builtin -after non-special builtin: 0 +after non-special builtin: 1 ./errors7.sub: line 25: x: readonly variable ./errors7.sub: line 27: x: readonly variable ./errors8.sub: eval: line 7: syntax error: unexpected end of file diff --git a/tests/extglob.right b/tests/extglob.right index 691f6879..d050bddc 100644 --- a/tests/extglob.right +++ b/tests/extglob.right @@ -114,3 +114,13 @@ a b c .x .y .z a b c .x .y .z a b c * +.. .b a +.. .b a +a .. .b +. .. .b +. .. .b +.. .b a +.. .b a +a .. .b +. .. .b +. .. .b diff --git a/tests/extglob.tests b/tests/extglob.tests index 4cb671a8..78001809 100644 --- a/tests/extglob.tests +++ b/tests/extglob.tests @@ -389,4 +389,6 @@ ${THIS_SH} ./extglob4.sub ${THIS_SH} ./extglob5.sub +${THIS_SH} ./extglob6.sub + exit 0 diff --git a/tests/extglob6.sub b/tests/extglob6.sub new file mode 100644 index 00000000..a5f3e6b2 --- /dev/null +++ b/tests/extglob6.sub @@ -0,0 +1,41 @@ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# issues with ? matching "." in certain special circumstances with dotglob set + +shopt -s dotglob extglob + +DIR=$TMPDIR/extglob-$$ +mkdir $DIR +cd $DIR + +touch a .b + +echo @(?|.?) +echo @(.?|?) +echo ? .? + +echo .* +echo \.* + +shopt -u dotglob + +echo @(?|.?) +echo @(.?|?) +echo ? .? + +echo .* +echo \.* + +cd $OLDPWD +rm -rf $DIR