From 5bf9b550c0adec566a39b7c5ccad6c8270e7d001 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 6 Nov 2017 09:19:55 -0500 Subject: [PATCH] commit bash-20171103 snapshot --- CWRU/CWRU.chlog | 34 ++++++++++++++++++++++++++++++++++ builtins/declare.def | 2 +- builtins/pushd.def | 2 +- lib/readline/isearch.c | 10 ++++++++-- parse.y | 4 +++- tests/comsub.tests | 6 ++++++ 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 48e0d987..f27c8a41 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -14399,3 +14399,37 @@ parse.y buffer when checking for the here doc delimiter. Report from Jakub Wilk , the result of a fuzzing test. Pointer to place for the fix from Eduardo Bustamante + + 10/30 + ----- +builtins/pushd.def + - get_directory_stack: make sure the current directory (element 0 of + the stack) is passed to polite_directory_format under the same + conditions as the rest of the stack entries (flags & 1). Otherwise + something like `cd ${DIRSTACK[0]}' will fail. Fixes bug reported + by Steve Jones + +builtins/declare.def + - declare_internal: when checking for a `[' to see whether or not this + is an array variable declaration (declare -a foo[12]), make sure + we don't do the check if we're just dealing with shell functions. + Bug and pointer to fix from PJ Eby + + 11/1 + ---- +parse.y + - parse_comsub: if we read a four-character word followed by a break + character, and that word is not one of the reserved words, set + lex_rwlen to 0 since we are no longer in a reserved word. It only + hurts if another break character immediately follows, so that test + succeeds again. Turn off the RESWDOK flag only if it's not a shell + metacharacter, too. Fixes bug reported by Kjetil Torgrim Homme + + + 11/3 + ---- +lib/readline/isearch.c + - _rl_isearch_dispatch: if we are searching in reverse order, let + sline_index go to -1 to avoid searching the same line twice. It + gets reset right after that, so there's no danger of indexing into + the history line with a negative index. diff --git a/builtins/declare.def b/builtins/declare.def index cb944feb..baa7df6b 100644 --- a/builtins/declare.def +++ b/builtins/declare.def @@ -373,7 +373,7 @@ restart_new_var_name: compound_array_assign = simple_array_assign = 0; array_subscript_assignment = 0; subscript_start = (char *)NULL; - if (t = strchr (name, '[')) /* ] */ + if ((t = strchr (name, '[')) && (flags_on & att_function) == 0) /* ] */ { /* If offset != 0 we have already validated any array reference because assignment() calls skipsubscript() */ diff --git a/builtins/pushd.def b/builtins/pushd.def index 6579e4c8..71e04097 100644 --- a/builtins/pushd.def +++ b/builtins/pushd.def @@ -678,7 +678,7 @@ get_directory_stack (flags) d = "."; else { - t = polite_directory_format (d); + t = (flags&1) ? polite_directory_format (d) : d; /* polite_directory_format sometimes returns its argument unchanged. If it does not, we can free d right away. If it does, we need to mark d to be deleted later. */ diff --git a/lib/readline/isearch.c b/lib/readline/isearch.c index da9f0cef..fa58e848 100644 --- a/lib/readline/isearch.c +++ b/lib/readline/isearch.c @@ -516,7 +516,7 @@ add_character: } return (1); } - else if (cxt->sflags & SF_REVERSE && cxt->sline_index > 0) + else if ((cxt->sflags & SF_REVERSE) && cxt->sline_index >= 0) cxt->sline_index--; else if (cxt->sline_index != cxt->sline_len) cxt->sline_index++; @@ -665,6 +665,7 @@ add_character: } else cxt->sline_index += cxt->direction; + if (cxt->sline_index < 0) { cxt->sline_index = 0; @@ -697,7 +698,12 @@ add_character: (cxt->search_string_index > cxt->sline_len)); if (cxt->sflags & SF_FAILED) - break; + { + /* XXX - reset sline_index if < 0 */ + if (cxt->sline_index < 0) + cxt->sline_index = 0; + break; + } /* Now set up the line for searching... */ cxt->sline_index = (cxt->sflags & SF_REVERSE) ? cxt->sline_len - cxt->search_string_index : 0; diff --git a/parse.y b/parse.y index 252310c6..af9ae5f8 100644 --- a/parse.y +++ b/parse.y @@ -4079,11 +4079,13 @@ eof_error: tflags |= LEX_RESWDOK; lex_rwlen = 0; } - else + else if (shellmeta (ch) == 0) { tflags &= ~LEX_RESWDOK; /*itrace("parse_comsub:%d: found `%.4s', lex_reswdok -> 0", line_number, ret+retind-4);*/ } + else /* can't be in a reserved word any more */ + lex_rwlen = 0; } else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0))) ; /* don't modify LEX_RESWDOK if we're starting a comment */ diff --git a/tests/comsub.tests b/tests/comsub.tests index dbae1e3a..ed56007c 100644 --- a/tests/comsub.tests +++ b/tests/comsub.tests @@ -50,6 +50,12 @@ do : done +# problem with four-character words followed by a metachar through bash-4.4 +comsub_foo_1() +{ + echo $(while true; do case $HOME in /*) echo abs ;; esac; done) +} + ${THIS_SH} ./comsub1.sub ${THIS_SH} ./comsub2.sub ${THIS_SH} ./comsub3.sub