From: Chet Ramey Date: Thu, 10 Jan 2019 16:56:16 +0000 (-0500) Subject: commit bash-20190109 snapshot X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=605528a7c0bb69456703fa4a9bef5b5bcc63d3f7;p=thirdparty%2Fbash.git commit bash-20190109 snapshot --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 7367e0bf0..30124c559 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -4970,12 +4970,6 @@ lib/glob/glob_loop.c 1/6/2019 -------- -execute_cmd.c - - execute_simple_command: catch all non-zero special builtin errors - (e.g. return not in a function) and make sure a non-interactive - posix-mode shell exits. Old code expected builtins to signal - internal fatal errors with code > 256. Fixes bug reported by - Robert Hailey examples/loadables/basename.c - make sure to include bashgetopt.h. Reported by Angel @@ -4993,3 +4987,42 @@ lib/readline/unicode.c - u32toutf16: correct the second argument to be wchar_t *, and treat it as such, even though it doesn't make a difference in practice. Report and fix from Eduardo Bustamante + + 1/8 + --- + +builtins/return.def + - return_builtin: return EX_USAGE if we're not executing a shell + function or sourcing a script, so a posix-mode shell exits. Fixes + bug reported by Robert Hailey + +builtins/declare.def + - declare_internal: don't let `declare -f +f' turn off the function + attribute. Fix from Grisha Levit + - declare_internal: reject attempts to add the -A or -a attributes + to functions. Report from Grisha Levit + + 1/9 + --- +bashline.c + - completion_glob_pattern: new function, returns true if the passed + string contains a glob pattern that should be process by the glob + completion code. Completion glob patterns don't pay attention to + backslashes unless they're the last character in the string. This + is a different, more self-contained, fix for the problem reported + by Tom Ryder + +lib/glob/glob_loop.c + - INTERNAL_GLOB_PATTERN_P: restore change from 4/27 and make this + function return non-zero if it encounters a backslash in the string. + It needs to match pathexp.c:unquoted_glob_pattern_p(). Adds fix + back for issue reported by axel@freakout.de + +test.c + - arithcomp: when calling evalexp, make sure to call it with the + EXP_EXPANDED flag, since all arguments here have been evaluated + already + +arrayfunc.c + - array_expand_index: call evalexp with EXP_EXPANDED flag, since we + have run the string through expand_arith_string already diff --git a/arrayfunc.c b/arrayfunc.c index e4ae34d05..7631e5ab6 100644 --- a/arrayfunc.c +++ b/arrayfunc.c @@ -963,7 +963,7 @@ array_expand_index (var, s, len, flags) t = expand_arith_string (exp, Q_DOUBLE_QUOTES|Q_ARITH|Q_ARRAYSUB); /* XXX - Q_ARRAYSUB for future use */ savecmd = this_command_name; this_command_name = (char *)NULL; - val = evalexp (t, 0, &expok); + val = evalexp (t, EXP_EXPANDED, &expok); /* XXX - was 0 but we expanded exp already */ this_command_name = savecmd; if (t != exp) free (t); diff --git a/bashline.c b/bashline.c index 2846aabf7..ff79b7048 100644 --- a/bashline.c +++ b/bashline.c @@ -1,6 +1,6 @@ /* bashline.c -- Bash's interface to the readline library. */ -/* Copyright (C) 1987-2017 Free Software Foundation, Inc. +/* Copyright (C) 1987-2019 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -231,6 +231,7 @@ static int bash_possible_variable_completions __P((int, int)); static int bash_complete_command __P((int, int)); static int bash_possible_command_completions __P((int, int)); +static int completion_glob_pattern __P((const char *)); static char *glob_complete_word __P((const char *, int)); static int bash_glob_completion_internal __P((int)); static int bash_glob_complete_word __P((int, int)); @@ -1741,7 +1742,7 @@ bash_default_completion (text, start, end, qc, compflags) /* This could be a globbing pattern, so try to expand it using pathname expansion. */ - if (!matches && glob_pattern_p (text)) + if (!matches && completion_glob_pattern (text)) { matches = rl_completion_matches (text, glob_complete_word); /* A glob expression that matches more than one filename is problematic. @@ -1850,7 +1851,7 @@ command_word_completion_function (hint_text, state) glob_matches = (char **)NULL; } - globpat = glob_pattern_p (hint_text); + globpat = completion_glob_pattern (hint_text); /* If this is an absolute program name, do not check it against aliases, reserved words, functions or builtins. We must check @@ -3713,6 +3714,61 @@ bash_complete_command_internal (what_to_do) return bash_specific_completion (what_to_do, command_word_completion_function); } +static int +completion_glob_pattern (string) + const char *string; +{ + register int c; + char *send; + int open; + + DECLARE_MBSTATE; + + open = 0; + send = string + strlen (string); + + while (c = *string++) + { + switch (c) + { + case '?': + case '*': + return (1); + + case '[': + open++; + continue; + + case ']': + if (open) + return (1); + continue; + + case '+': + case '@': + case '!': + if (*string == '(') /*)*/ + return (1); + continue; + + case '\\': + if (*string == 0) + return (0); + } + + /* Advance one fewer byte than an entire multibyte character to + account for the auto-increment in the loop above. */ +#ifdef HANDLE_MULTIBYTE + string--; + ADVANCE_CHAR_P (string, send - string); + string++; +#else + ADVANCE_CHAR_P (string, send - string); +#endif + } + return (0); +} + static char *globtext; static char *globorig; @@ -3877,7 +3933,7 @@ bash_vi_complete (count, key) t = substring (rl_line_buffer, p, rl_point); } - if (t && glob_pattern_p (t) == 0) + if (t && completion_glob_pattern (t) == 0) rl_explicit_arg = 1; /* XXX - force glob_complete_word to append `*' */ FREE (t); diff --git a/builtins/declare.def b/builtins/declare.def index 7eac6f583..3fd1eb64f 100644 --- a/builtins/declare.def +++ b/builtins/declare.def @@ -533,7 +533,12 @@ restart_new_var_name: any_failed++; NEXT_VARIABLE (); } - + else if (flags_on & (att_array|att_assoc)) + { + sh_invalidopt ((flags_on & att_array) ? "-a" : "-A"); + any_failed++; + NEXT_VARIABLE (); + } /* declare -[Ff] name [name...] */ if (flags_on == att_function && flags_off == 0) { @@ -558,6 +563,7 @@ restart_new_var_name: else /* declare -[fF] -[rx] name [name...] */ { VSETATTR (var, flags_on); + flags_off &= ~att_function; /* makes no sense */ VUNSETATTR (var, flags_off); } } diff --git a/builtins/return.def b/builtins/return.def index 77e8d7c78..03c98eb11 100644 --- a/builtins/return.def +++ b/builtins/return.def @@ -66,6 +66,6 @@ return_builtin (list) else { builtin_error (_("can only `return' from a function or sourced script")); - return (EXECUTION_FAILURE); + return (EX_USAGE); } } diff --git a/examples/loadables/push.c b/examples/loadables/push.c index 9bcd5c324..194487c0c 100644 --- a/examples/loadables/push.c +++ b/examples/loadables/push.c @@ -35,7 +35,7 @@ extern int errno; #endif -extern int dollar_dollar_pid; +extern pid_t dollar_dollar_pid; extern int last_command_exit_value; int diff --git a/execute_cmd.c b/execute_cmd.c index 75b9804b4..686ecfe94 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -4504,8 +4504,6 @@ run_builtin: if (builtin_is_special) special_builtin_failed = 1; /* XXX - take command builtin into account? */ } - else - special_builtin_failed = builtin_is_special && result != EXECUTION_SUCCESS; /* In POSIX mode, if there are assignment statements preceding a special builtin, they persist after the builtin diff --git a/lib/glob/glob_loop.c b/lib/glob/glob_loop.c index 5f319cc2e..7d6ae2113 100644 --- a/lib/glob/glob_loop.c +++ b/lib/glob/glob_loop.c @@ -54,17 +54,11 @@ INTERNAL_GLOB_PATTERN_P (pattern) continue; case L('\\'): -#if 0 /* Don't let the pattern end in a backslash (GMATCH returns no match if the pattern ends in a backslash anyway), but otherwise return 1, since the matching engine uses backslash as an escape character and it can be removed. */ return (*p != L('\0')); -#else - /* The pattern may not end with a backslash. */ - if (*p++ == L('\0')) - return 0; -#endif } return 0; diff --git a/subst.c b/subst.c index 95591878c..4173547d2 100644 --- a/subst.c +++ b/subst.c @@ -3565,6 +3565,10 @@ expand_arith_string (string, quoted) /* This is expanded version of expand_string_internal as it's called by expand_string_leave_quoted */ td.flags = W_NOPROCSUB|W_NOTILDE; /* don't want process substitution or tilde expansion */ +#if 0 /* TAG:bash-5.1 */ + if (quoted & Q_ARRAYSUB) + td.flags |= W_NOCOMSUB; +#endif td.word = savestring (string); list = call_expand_word_internal (&td, quoted, 0, (int *)NULL, (int *)NULL); /* This takes care of the calls from expand_string_leave_quoted and diff --git a/test.c b/test.c index 4cb3343cd..f007be8fe 100644 --- a/test.c +++ b/test.c @@ -344,10 +344,10 @@ arithcomp (s, t, op, flags) if (flags & TEST_ARITHEXP) { - l = evalexp (s, 0, &expok); + l = evalexp (s, EXP_EXPANDED, &expok); if (expok == 0) return (FALSE); /* should probably longjmp here */ - r = evalexp (t, 0, &expok); + r = evalexp (t, EXP_EXPANDED, &expok); if (expok == 0) return (FALSE); /* ditto */ } diff --git a/tests/glob.right b/tests/glob.right index 1ead7b61d..964d83d1e 100644 --- a/tests/glob.right +++ b/tests/glob.right @@ -61,6 +61,8 @@ a? argv[1] = a? aa + argv[1] = argv[2] = argv[3] = diff --git a/tests/glob4.sub b/tests/glob4.sub index 378b5a926..2733eb77c 100644 --- a/tests/glob4.sub +++ b/tests/glob4.sub @@ -11,3 +11,9 @@ printf "%s\n" ${var} var='a\a' printf "%s\n" ${var} + +# shell's idea of a glob pattern and libglob's idea of a glob pattern have to +# be identical +PRE='\/' +printf '<%s>\n' 'define'${PRE}'\ +/'