From 9282e182d874a98a25a35cb7b1682b6e45e5af50 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 17 Sep 2018 11:46:57 -0400 Subject: [PATCH] commit bash-20180914 snapshot --- CHANGES | 2 +- CHANGES-5.0 | 2 +- CWRU/CWRU.chlog | 46 +++++++++++++++++++++++++++++++++++++++ builtins/exec.def | 6 +++++ configure | 4 ++-- configure.ac | 4 ++-- execute_cmd.c | 2 +- expr.c | 6 ++++- jobs.c | 8 ++++++- jobs.h | 1 + lib/readline/histexpand.c | 8 ++++--- lib/readline/undo.c | 27 ++++++++++++++++++++++- tests/RUN-ONE-TEST | 2 +- tests/glob.tests | 2 +- tests/histexp.right | 2 ++ tests/histexp6.sub | 1 + tests/procsub.tests | 18 ++++++++++----- tests/run-glob-test | 7 ++++-- tests/run-nquote4 | 8 +++++-- 19 files changed, 131 insertions(+), 25 deletions(-) diff --git a/CHANGES b/CHANGES index ba97f0a6..bce097c4 100644 --- a/CHANGES +++ b/CHANGES @@ -79,7 +79,7 @@ e. Fixes to the vi-mode `b', `B', `w', `W', `e', and `E' commands to better handle multibyte characters. f. Fixed a redisplay problem that caused an extra newline to be generated on - accept-line when the line is exactly the screenwidth. + accept-line when the line length is exactly the screenwidth. 3. New Features in Bash diff --git a/CHANGES-5.0 b/CHANGES-5.0 index b140903e..a1619a74 100644 --- a/CHANGES-5.0 +++ b/CHANGES-5.0 @@ -79,7 +79,7 @@ e. Fixes to the vi-mode `b', `B', `w', `W', `e', and `E' commands to better handle multibyte characters. f. Fixed a redisplay problem that caused an extra newline to be generated on - accept-line when the line is exactly the screenwidth. + accept-line when the line length is exactly the screenwidth. 3. New Features in Bash diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 9f00b946..7ce075c2 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -4303,3 +4303,49 @@ configure.ac - openbsd needs DEV_FD_STAT_BROKEN defined [bash-5.0-beta frozen] + + 9/11 + ---- +builtins/exec.def + - exec_builtin: make sure to sync the buffered stream where bash is + reading input (especially if it's fd 0) so a command exec'd by the + script can read the rest of stdin after the exec + + 9/15 + ---- +lib/readline/histexpand.c + - history_tokenize_internal: if the event contains embedded newlines + (e.g., bash with command-oriented history and lithist), use them as + word delimiters, equivalent to space and tab, so they don't end up + as separate words. Fixes issue pointed out by Viktor Dukhovni + + - history_tokenize_word: don't break if we get a newline (though we + shouldn't get one due to the loop in history_tokenize_internal + - history_expand_internal: use newline as a whitespace character when + expanding by words, as we do with history_tokenize_internal + +jobs.h + - J_PIPEFAIL: new flag for `flags' element of job struct + +jobs.c + - stop_pipeline: if pipefail_opt set, newjob gets J_PIPEFAIL in its + flags word + - raw_job_exit_status: use J_PIPEFAIL (setting of pipefail when job + created) instead of current setting of pipefail status to determine + how to compute exit status of pipeline. Tentative implementation of + Posix proposal + +expr.c + - exp0: don't call expr_bind_variable with a NULL string. Fixes + fuzzing bug reported by Eduardo Bustamante + - expr_bind_variable: don't try to do anything with a NULL or empty + LHS + + 9/16 + ---- +lib/readline/undo.c + - rl_do_undo: before we release the undo list entry we've just + processed, make sure we avoid any pointer aliasing issues caused + by having the entry being removed as part of the undo list in + _rl_saved_line_for_history. Fixes fuzzing bug reported by + Eduardo Bustamante diff --git a/builtins/exec.def b/builtins/exec.def index 4bf51d9d..d4670673 100644 --- a/builtins/exec.def +++ b/builtins/exec.def @@ -68,6 +68,7 @@ $END #endif #include "common.h" #include "bashgetopt.h" +#include "input.h" /* Not all systems declare ERRNO in errno.h... and some systems #define it! */ #if !defined (errno) @@ -221,6 +222,11 @@ exec_builtin (list) default_tty_job_signals (); /* undo initialize_job_signals */ #endif /* JOB_CONTROL */ +#if defined (BUFFERED_INPUT) + if (default_buffered_input >= 0) + sync_buffered_stream (default_buffered_input); +#endif + exit_value = shell_execve (command, args, env); /* We have to set this to NULL because shell_execve has called realloc() diff --git a/configure b/configure index dd4ff051..76326a12 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac for Bash 5.0, version 5.002. +# From configure.ac for Bash 5.0, version 5.003. # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.69 for bash 5.0-beta. # @@ -16180,7 +16180,7 @@ linux*) LOCAL_LDFLAGS=-rdynamic # allow dynamic loading *) $as_echo "#define PGRP_PIPE 1" >>confdefs.h ;; esac ;; -openbsd*) LOCAL_CFLAGS="-DDEV_FD_STAT_BROKEN" ;; +netbsd*|openbsd*) LOCAL_CFLAGS="-DDEV_FD_STAT_BROKEN" ;; *qnx[67]*) LOCAL_LIBS="-lncurses" ;; *qnx*) LOCAL_CFLAGS="-Dqnx -F -3s" LOCAL_LDFLAGS="-3s" LOCAL_LIBS="-lunix -lncurses" ;; powerux*) LOCAL_LIBS="-lgen" ;; diff --git a/configure.ac b/configure.ac index 5ead2016..e848b7f7 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ dnl Process this file with autoconf to produce a configure script. # You should have received a copy of the GNU General Public License # along with this program. If not, see . -AC_REVISION([for Bash 5.0, version 5.002])dnl +AC_REVISION([for Bash 5.0, version 5.003])dnl define(bashvers, 5.0) define(relstatus, beta) @@ -1116,7 +1116,7 @@ linux*) LOCAL_LDFLAGS=-rdynamic # allow dynamic loading 1.*|2.[[0123]]*) : ;; *) AC_DEFINE(PGRP_PIPE) ;; esac ;; -openbsd*) LOCAL_CFLAGS="-DDEV_FD_STAT_BROKEN" ;; +netbsd*|openbsd*) LOCAL_CFLAGS="-DDEV_FD_STAT_BROKEN" ;; *qnx[[67]]*) LOCAL_LIBS="-lncurses" ;; *qnx*) LOCAL_CFLAGS="-Dqnx -F -3s" LOCAL_LDFLAGS="-3s" LOCAL_LIBS="-lunix -lncurses" ;; powerux*) LOCAL_LIBS="-lgen" ;; diff --git a/execute_cmd.c b/execute_cmd.c index c5972c8d..1c95a93b 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -748,7 +748,7 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out, reap_procsubs (); # endif - if (variable_context != 0) + if (variable_context != 0) /* XXX - also if sourcelevel != 0? */ { ofifo = num_fifos (); ofifo_list = copy_fifo_list ((int *)&osize); diff --git a/expr.c b/expr.c index c51240f4..cc7c9e9a 100644 --- a/expr.c +++ b/expr.c @@ -325,6 +325,9 @@ expr_bind_variable (lhs, rhs) SHELL_VAR *v; int aflags; + if (lhs == 0 || *lhs == 0) + return; /* XXX */ + #if defined (ARRAY_VARS) aflags = (assoc_expand_once && already_expanded) ? ASS_NOEXPAND : 0; #else @@ -1012,7 +1015,8 @@ exp0 () expr_bind_array_element (curlval.tokstr, curlval.ind, vincdec); else #endif - expr_bind_variable (tokstr, vincdec); + if (tokstr) + expr_bind_variable (tokstr, vincdec); } free (vincdec); val = v2; diff --git a/jobs.c b/jobs.c index f517a248..1f6c8091 100644 --- a/jobs.c +++ b/jobs.c @@ -630,6 +630,8 @@ stop_pipeline (async, deferred) pipeline_pgrp = 0; newjob->flags = 0; + if (pipefail_opt) + newjob->flags |= J_PIPEFAIL; /* Flag to see if in another pgrp. */ if (job_control) @@ -688,7 +690,7 @@ stop_pipeline (async, deferred) { newjob->flags |= J_FOREGROUND; /* - * !!!!! NOTE !!!!! (chet@ins.cwru.edu) + * !!!!! NOTE !!!!! (chet@po.cwru.edu) * * The currently-accepted job control wisdom says to set the * terminal's process group n+1 times in an n-step pipeline: @@ -2639,7 +2641,11 @@ raw_job_exit_status (job) int fail; WAIT ret; +#if 0 if (pipefail_opt) +#else + if (jobs[job]->flags & J_PIPEFAIL) +#endif { fail = 0; p = jobs[job]->pipe; diff --git a/jobs.h b/jobs.h index 6ebaf4de..de939c0d 100644 --- a/jobs.h +++ b/jobs.h @@ -103,6 +103,7 @@ typedef enum { JNONE = -1, JRUNNING = 1, JSTOPPED = 2, JDEAD = 4, JMIXED = 8 } J #define J_NOHUP 0x08 /* Don't send SIGHUP to job if shell gets SIGHUP. */ #define J_STATSAVED 0x10 /* A process in this job had had status saved via $! */ #define J_ASYNC 0x20 /* Job was started asynchronously */ +#define J_PIPEFAIL 0x40 /* pipefail set when job was started */ #define IS_FOREGROUND(j) ((jobs[j]->flags & J_FOREGROUND) != 0) #define IS_NOTIFIED(j) ((jobs[j]->flags & J_NOTIFIED) != 0) diff --git a/lib/readline/histexpand.c b/lib/readline/histexpand.c index 92b996f9..adcf5dcb 100644 --- a/lib/readline/histexpand.c +++ b/lib/readline/histexpand.c @@ -55,6 +55,8 @@ #define slashify_in_quotes "\\`\"$" +#define fielddelim(c) (whitespace(c) || (c) == '\n') + typedef int _hist_search_func_t PARAMS((const char *, int)); static char error_pointer; @@ -769,7 +771,7 @@ history_expand_internal (char *string, int start, int qc, int *end_index_ptr, ch the last time. */ if (subst_bywords && si > we) { - for (; temp[si] && whitespace (temp[si]); si++) + for (; temp[si] && fielddelim (temp[si]); si++) ; ws = si; we = history_tokenize_word (temp, si); @@ -1446,7 +1448,7 @@ history_tokenize_word (const char *string, int ind) i = ind; delimiter = nestdelim = 0; - if (member (string[i], "()\n")) + if (member (string[i], "()\n")) /* XXX - included \n, but why? been here forever */ { i++; return i; @@ -1604,7 +1606,7 @@ history_tokenize_internal (const char *string, int wind, int *indp) for (i = result_index = size = 0, result = (char **)NULL; string[i]; ) { /* Skip leading whitespace. */ - for (; string[i] && whitespace (string[i]); i++) + for (; string[i] && fielddelim (string[i]); i++) ; if (string[i] == 0 || string[i] == history_comment_char) return (result); diff --git a/lib/readline/undo.c b/lib/readline/undo.c index 75874e5d..ae65d380 100644 --- a/lib/readline/undo.c +++ b/lib/readline/undo.c @@ -51,6 +51,8 @@ extern void _hs_replace_history_data PARAMS((int, histdata_t *, histdata_t *)); +extern HIST_ENTRY *_rl_saved_line_for_history; + /* Non-zero tells rl_delete_text and rl_insert_text to not add to the undo list. */ int _rl_doing_an_undo = 0; @@ -166,7 +168,7 @@ _rl_copy_undo_list (UNDO_LIST *head) int rl_do_undo (void) { - UNDO_LIST *release; + UNDO_LIST *release, *search; int waiting_for_begin, start, end; HIST_ENTRY *cur, *temp; @@ -223,6 +225,7 @@ rl_do_undo (void) release = rl_undo_list; rl_undo_list = rl_undo_list->next; + release->next = 0; /* XXX */ /* If we are editing a history entry, make sure the change is replicated in the history entry's line */ @@ -235,8 +238,30 @@ rl_do_undo (void) xfree (temp); } + /* Make sure there aren't any history entries with that undo list */ _hs_replace_history_data (-1, (histdata_t *)release, (histdata_t *)rl_undo_list); + /* And make sure this list isn't anywhere in the saved line for history */ + if (_rl_saved_line_for_history && _rl_saved_line_for_history->data) + { + /* Brute force; no finesse here */ + search = (UNDO_LIST *)_rl_saved_line_for_history->data; + if (search == release) + _rl_saved_line_for_history->data = rl_undo_list; + else + { + while (search->next) + { + if (search->next == release) + { + search->next = rl_undo_list; + break; + } + search = search->next; + } + } + } + xfree (release); } while (waiting_for_begin); diff --git a/tests/RUN-ONE-TEST b/tests/RUN-ONE-TEST index 58c375b7..554f3d6e 100755 --- a/tests/RUN-ONE-TEST +++ b/tests/RUN-ONE-TEST @@ -1,4 +1,4 @@ -BUILD_DIR=/usr/local/build/chet/bash/bash-current +BUILD_DIR=/usr/local/build/bash/bash-current THIS_SH=$BUILD_DIR/bash PATH=$PATH:$BUILD_DIR diff --git a/tests/glob.tests b/tests/glob.tests index 7ae51723..cfb086fd 100644 --- a/tests/glob.tests +++ b/tests/glob.tests @@ -4,7 +4,7 @@ export LC_COLLATE=C # expect() { - echo expect "$@" +: # if needed, change me to echo expect "$@" } # First, a test that bash-2.01.1 fails diff --git a/tests/histexp.right b/tests/histexp.right index 1eeb39fb..9dc592cb 100644 --- a/tests/histexp.right +++ b/tests/histexp.right @@ -231,6 +231,7 @@ echo one 1 set -o histexpand 2 echo one 3 for f in a b c; do echo echo one; done + 4 history two echo echo two echo two @@ -238,3 +239,4 @@ echo two echo two 1 echo two 2 for f in a b c; do echo echo two; done + 3 history diff --git a/tests/histexp6.sub b/tests/histexp6.sub index b95b460a..00610b07 100644 --- a/tests/histexp6.sub +++ b/tests/histexp6.sub @@ -1,3 +1,4 @@ +unset HISTIGNORE HISTFILE=$TMPDIR/bashhist-$$ set -o history diff --git a/tests/procsub.tests b/tests/procsub.tests index 4678ac69..01ba46a8 100644 --- a/tests/procsub.tests +++ b/tests/procsub.tests @@ -68,6 +68,12 @@ unset -f bug count_lines() { wc -l < $1 + +# case "$1" in +# *sh-np*) [ -e "$1" ] || { echo 0; echo 0; echo 0; echo 0; return; } ;; +# *) ;; +# esac + wc -l < $1 wc -l < $1 true | wc -l < $1 @@ -80,12 +86,12 @@ unset -f count_lines echo extern FN=$TMPDIR/bashtest-$$ -cat >$FN <$FN << \EOF +wc -l < $1 +wc -l < $1 +wc -l < $1 +true | wc -l < $1 +wc -l < $1 EOF ${THIS_SH} -c "source $FN <(date)" | _cut_leading_spaces diff --git a/tests/run-glob-test b/tests/run-glob-test index 43aa276f..246501cc 100644 --- a/tests/run-glob-test +++ b/tests/run-glob-test @@ -1,4 +1,7 @@ PATH=$PATH:`pwd` export PATH -${THIS_SH} ./glob.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} -diff ${BASH_TSTOUT} glob.right && rm -f ${BASH_TSTOUT} + +( diff -a glob.right glob.right >/dev/null 2>&1 ) && AFLAG=-a + +${THIS_SH} ./glob.tests > ${BASH_TSTOUT} 2>&1 +diff ${AFLAG} ${BASH_TSTOUT} glob.right && rm -f ${BASH_TSTOUT} diff --git a/tests/run-nquote4 b/tests/run-nquote4 index 44baac4c..985c3111 100644 --- a/tests/run-nquote4 +++ b/tests/run-nquote4 @@ -1,4 +1,8 @@ +# See whether or not we can use `diff -a' +( diff -a ./nquote4.right ./nquote4.right >/dev/null 2>&1 ) && AFLAG=-a + echo warning: some of these tests will fail if you do not have UTF-8 >&2 echo warning: locales installed on your system >&2 -${THIS_SH} ./nquote4.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} -diff ${BASH_TSTOUT} nquote4.right && rm -f ${BASH_TSTOUT} + +${THIS_SH} ./nquote4.tests > ${BASH_TSTOUT} 2>&1 +diff ${AFLAG} ${BASH_TSTOUT} nquote4.right && rm -f ${BASH_TSTOUT}