From: Chet Ramey Date: Fri, 5 Jun 2015 15:48:51 +0000 (-0400) Subject: commit bash-20150515 snapshot X-Git-Tag: bash-4.4-alpha~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=74b8cbb41398b4453d8ba04d0cdd1b25f9dcb9e3;p=thirdparty%2Fbash.git commit bash-20150515 snapshot --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 1edc56040..5f5254264 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -8518,3 +8518,43 @@ subst.c - pat_subst: change to allow empty strings to be replaced as long as pattern matches empty string. Report and fix from isabella parakiss + + 5/12 + ---- +lib/sh/strtrans.c + - ansic_wshouldquote: make behavior consistent in the event of an + invalid multibyte sequence: return 1 to the caller so the string + will be $'...' quoted + +builtins/cd.def + - cd_builtin: print the right error message even if printable_filename + changes errno (e.g., EILSEQ) + +lib/sh/shquote.c + - sh_backslash_quote: in multibyte locales, even if is_basic does not + return true, backslash-quote an ASCII character that backslash_table + says should be quoted. Part of fix for bug reported by Igor + Bogomazov + +bashline.c + - directory_exists: new function, dequotes the string argument, removes + any trailing slash, and returns true if the result is a valid + existing filename + - bash_filename_stat_hook,bash_directory_completion_hook: use + directory_exists instead of calling lstat/stat on the quoted + directory name. Rest of fix for bug reported by Igor Bogomazov + + + 5/15 + ---- +aclocal.m4 + - BASH_CHECK_MULTIBYTE: when checking for locale_charset, add $LIBINTL to + $LIBS. If we're using the included lib/intl/libintl.a, it will include + a version of locale_charset + + 5/17 + ---- +lib/readline/bind.c + - sv_isrchterm: make sure we check for v[end] == 0 while in the loop + looking for whitespace. Bug report and fix from Sergio Durigan + Junior diff --git a/aclocal.m4 b/aclocal.m4 index 105b886e3..7730d2d9c 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1793,7 +1793,7 @@ fi if test "$am_cv_func_iconv" = yes; then OLDLIBS="$LIBS" - LIBS="$LIBS $LIBICONV" + LIBS="$LIBS $LIBINTL $LIBICONV" AC_CHECK_FUNCS(locale_charset) LIBS="$OLDLIBS" fi diff --git a/bashline.c b/bashline.c index f81103aff..1cef29efa 100644 --- a/bashline.c +++ b/bashline.c @@ -141,6 +141,8 @@ static int executable_completion __P((const char *, int)); static rl_icppfunc_t *save_directory_hook __P((void)); static void restore_directory_hook __P((rl_icppfunc_t)); +static int directory_exists __P((const char *)); + static void cleanup_expansion_error __P((void)); static void maybe_make_readline_line __P((char *)); static void set_up_new_line __P((char *)); @@ -3077,6 +3079,30 @@ restore_directory_hook (hookf) rl_directory_rewrite_hook = hookf; } +/* Check whether not the (dequoted) version of DIRNAME, with any trailing slash + removed, exists. */ +static int +directory_exists (dirname) + const char *dirname; +{ + char *new_dirname; + int dirlen, r; + struct stat sb; + + /* First, dequote the directory name */ + new_dirname = bash_dequote_filename (dirname, rl_completion_quote_character); + dirlen = STRLEN (new_dirname); + if (new_dirname[dirlen - 1] == '/') + new_dirname[dirlen - 1] = '\0'; +#if defined (HAVE_LSTAT) + r = lstat (new_dirname, &sb) == 0; +#else + r = stat (new_dirname, &sb) == 0; +#endif + free (new_dirname); + return (r); +} + /* Expand a filename before the readline completion code passes it to stat(2). The filename will already have had tilde expansion performed. */ static int @@ -3095,11 +3121,7 @@ bash_filename_stat_hook (dirname) else if (t = mbschr (local_dirname, '`')) /* XXX */ should_expand_dirname = '`'; -#if defined (HAVE_LSTAT) - if (should_expand_dirname && lstat (local_dirname, &sb) == 0) -#else - if (should_expand_dirname && stat (local_dirname, &sb) == 0) -#endif + if (should_expand_dirname && directory_exists (local_dirname)) should_expand_dirname = 0; if (should_expand_dirname) @@ -3163,7 +3185,8 @@ bash_directory_completion_hook (dirname) char **dirname; { char *local_dirname, *new_dirname, *t; - int return_value, should_expand_dirname, nextch, closer; + int return_value, should_expand_dirname, nextch, closer, changed; + size_t local_dirlen; WORD_LIST *wl; struct stat sb; @@ -3192,11 +3215,7 @@ bash_directory_completion_hook (dirname) should_expand_dirname = '`'; } -#if defined (HAVE_LSTAT) - if (should_expand_dirname && lstat (local_dirname, &sb) == 0) -#else - if (should_expand_dirname && stat (local_dirname, &sb) == 0) -#endif + if (should_expand_dirname && directory_exists (local_dirname)) should_expand_dirname = 0; if (should_expand_dirname) diff --git a/builtins/cd.def b/builtins/cd.def index a2ffd3330..43a181a82 100644 --- a/builtins/cd.def +++ b/builtins/cd.def @@ -262,7 +262,7 @@ cd_builtin (list) WORD_LIST *list; { char *dirname, *cdpath, *path, *temp; - int path_index, no_symlinks, opt, lflag; + int path_index, no_symlinks, opt, lflag, e; #if defined (RESTRICTED_SHELL) if (restricted) @@ -437,8 +437,9 @@ cd_builtin (list) FREE (temp); } + e = errno; temp = printable_filename (dirname, 0); - builtin_error ("%s: %s", temp, strerror (errno)); + builtin_error ("%s: %s", temp, strerror (e)); if (temp != dirname) free (temp); return (EXECUTION_FAILURE); diff --git a/configure b/configure index cf25ea2db..f289541b1 100755 --- a/configure +++ b/configure @@ -11423,7 +11423,7 @@ fi if test "$am_cv_func_iconv" = yes; then OLDLIBS="$LIBS" - LIBS="$LIBS $LIBICONV" + LIBS="$LIBS $LIBINTL $LIBICONV" for ac_func in locale_charset do : ac_fn_c_check_func "$LINENO" "locale_charset" "ac_cv_func_locale_charset" diff --git a/lib/readline/bind.c b/lib/readline/bind.c index 60af35acb..f88e5aad5 100644 --- a/lib/readline/bind.c +++ b/lib/readline/bind.c @@ -1859,7 +1859,7 @@ sv_isrchterm (value) } else { - for (beg = end = 0; whitespace (v[end]) == 0; end++) + for (beg = end = 0; v[end] && whitespace (v[end]) == 0; end++) ; } diff --git a/lib/sh/shquote.c b/lib/sh/shquote.c index e009b3767..4f13ab399 100644 --- a/lib/sh/shquote.c +++ b/lib/sh/shquote.c @@ -246,6 +246,13 @@ sh_backslash_quote (string, table, flags) for (r = result, s = string; s && (c = *s); s++) { #if defined (HANDLE_MULTIBYTE) + /* XXX - isascii, even if is_basic(c) == 0 - works in most cases. */ + if (c >= 0 && c <= 127 && backslash_table[(unsigned char)c] == 1) + { + *r++ = '\\'; + *r++ = c; + continue; + } if (MB_CUR_MAX > 1 && is_basic (c) == 0) { COPY_CHAR_P (r, s, send); diff --git a/lib/sh/strtrans.c b/lib/sh/strtrans.c index 02f5c89af..3bed4a612 100644 --- a/lib/sh/strtrans.c +++ b/lib/sh/strtrans.c @@ -312,8 +312,9 @@ ansic_wshouldquote (string) slen = mbstowcs (wcstr, string, 0); - if (slen == -1) - slen = 0; + if (slen == (size_t)-1) + return 1; + wcstr = (wchar_t *)xmalloc (sizeof (wchar_t) * (slen + 1)); mbstowcs (wcstr, string, slen + 1); diff --git a/tests/RUN-ONE-TEST b/tests/RUN-ONE-TEST index 72ec06a2c..3efcf32d6 100755 --- a/tests/RUN-ONE-TEST +++ b/tests/RUN-ONE-TEST @@ -1,4 +1,4 @@ -BUILD_DIR=/usr/local/build/bash/bash-current +BUILD_DIR=/usr/local/build/chet/bash/bash-current THIS_SH=$BUILD_DIR/bash PATH=$PATH:$BUILD_DIR diff --git a/tests/case.right b/tests/case.right index 58ab2a4fa..a17234b9f 100644 --- a/tests/case.right +++ b/tests/case.right @@ -7,6 +7,13 @@ no more clauses 1.0 ./case.tests: line 29: xx: readonly variable 1.1 +matches 1 +no +no +no +no +no +ok ok 1 ok 2 ok 3 diff --git a/tests/case.tests b/tests/case.tests index 547e8ccd6..7ab316a7e 100644 --- a/tests/case.tests +++ b/tests/case.tests @@ -29,5 +29,25 @@ readonly xx=1 case 1 in $((xx++)) ) echo hi1 ;; *) echo hi2; esac echo ${xx}.$? +unset var empty + +var= +case ']' in +[$var]*[$var]) echo matches 1;; +*) echo no match 1 ;; +esac + +case abc in ( [] ) echo yes ;; ( * ) echo no ;; esac +empty='' +case abc in ( ["$empty"] ) echo yes ;; ( * ) echo no ;; esac + +case abc in ( [] | [!a-z]* ) echo yes ;; ( * ) echo no ;; esac +empty='' +case abc in ( ["$empty"] | [!a-z]* ) echo yes ;; ( * ) echo no ;; esac + +case abc in (["$empty"]|[!a-z]*) echo yes ;; (*) echo no ;; esac + +case " " in ( [" "] ) echo ok;; ( * ) echo no;; esac + # tests of quote removal and pattern matching ${THIS_SH} ./case1.sub diff --git a/tests/intl.right b/tests/intl.right index df160e1fa..006318e59 100644 --- a/tests/intl.right +++ b/tests/intl.right @@ -50,6 +50,7 @@ Passed all 1378 Unicode tests 0000003 0000000 101 040 302 243 040 305 222 012 0000010 -./unicode3.sub: line 2: 5§@3™+ÆS8Ÿ¢ê³: command not found -5§@3™+ÆS8Ÿ¢ê³ +./unicode3.sub: line 3: $'5\247@3\231+\306S8\237\242\352\263': command not found +./unicode3.sub: line 5: cd: $'5\247@3\231+\306S8\237\242\352\263': No such file or directory +$'5\247@3\231+\306S8\237\242\352\263' + : $'5\247@3\231+\306S8\237\242\352\263' diff --git a/tests/new-exp.right b/tests/new-exp.right index 7366e07ae..b4e2a8e4e 100644 --- a/tests/new-exp.right +++ b/tests/new-exp.right @@ -254,6 +254,12 @@ argv[1] = argv[1] = argv[1] = argv[1] = +x +x +x +xabc +x +x argv[1] = argv[2] = argv[3] = @@ -405,13 +411,13 @@ argv[6] = argv[7] = argv[8] = argv[9] = -./new-exp.tests: line 490: $9: unbound variable -./new-exp.tests: line 491: 9: unbound variable -./new-exp.tests: line 492: UNSET: unbound variable -./new-exp.tests: line 493: UNSET: unbound variable -./new-exp.tests: line 494: UNSET: unbound variable -./new-exp.tests: line 495: UNSET: unbound variable -./new-exp.tests: line 496: UNSET: unbound variable +./new-exp.tests: line 503: $9: unbound variable +./new-exp.tests: line 504: 9: unbound variable +./new-exp.tests: line 505: UNSET: unbound variable +./new-exp.tests: line 506: UNSET: unbound variable +./new-exp.tests: line 507: UNSET: unbound variable +./new-exp.tests: line 508: UNSET: unbound variable +./new-exp.tests: line 509: UNSET: unbound variable argv[1] = <5> argv[1] = <#> argv[1] = <#> @@ -440,7 +446,7 @@ Case05---3---A:B:C--- Case06---1---A B C::--- Case07---3---A:B:C--- Case08---3---A:B:C--- -./new-exp.tests: line 516: ${$(($#-1))}: bad substitution +./new-exp.tests: line 529: ${$(($#-1))}: bad substitution argv[1] = argv[2] = argv[3] = @@ -457,7 +463,7 @@ argv[1] = argv[1] = argv[2] = argv[1] = <> -./new-exp.tests: line 535: $(($# - 2)): substring expression < 0 +./new-exp.tests: line 548: $(($# - 2)): substring expression < 0 argv[1] = argv[2] = argv[3] = @@ -621,4 +627,4 @@ a b c d e a5b argv[1] = argv[1] = -./new-exp.tests: line 595: ABXD: parameter unset +./new-exp.tests: line 608: ABXD: parameter unset diff --git a/tests/new-exp.tests b/tests/new-exp.tests index 666d8a9d2..c4aa9d167 100644 --- a/tests/new-exp.tests +++ b/tests/new-exp.tests @@ -452,6 +452,19 @@ recho ${xxx//%${zzz}} recho ${xxx//#${zzz}/} recho ${xxx//#${zzz}} +# make sure null strings are replaced appropriately +unset var +var= +echo "${var/#/x}" +echo "${var/*/x}" +echo "${var//*/x}" + +var=abc +echo "${var/#/x}" +echo "${var/*/x}" +echo "${var//*/x}" +unset var + # another case that caused a core dump in bash-2.0 XPATH=/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin::/usr/bin/X11:/sbin:/usr/sbin diff --git a/tests/unicode3.sub b/tests/unicode3.sub index f79871f61..b39f1d3ca 100644 --- a/tests/unicode3.sub +++ b/tests/unicode3.sub @@ -1,6 +1,8 @@ +export LANG=en_US.UTF-8 # make sure payload=$'\065\247\100\063\231\053\306\123\070\237\242\352\263' "$payload" +cd "$payload" printf %q "$payload" echo