From 5d31eaea6e4dd13162921a0e9160ba8ef601fb8d Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 15 Apr 2019 09:26:31 -0400 Subject: [PATCH] commit bash-20190412 snapshot --- CWRU/CWRU.chlog | 75 ++++++++++++++++++++++++++++++++++++ bashhist.c | 4 +- builtins/trap.def | 33 ++++++++++------ doc/version.texi | 6 +-- input.c | 2 +- jobs.c | 5 +-- lib/glob/glob.c | 2 + lib/readline/doc/rluser.texi | 2 +- lib/sh/zcatfd.c | 2 +- lib/sh/zmapfd.c | 6 +-- redir.c | 41 +++++++++++++++++++- subst.c | 13 ++++++- 12 files changed, 163 insertions(+), 28 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index e70b7195..2277e707 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -5711,3 +5711,78 @@ lib/readline/histfile.c - history_rename: wrapper function for rename(2) to deal with the Win32 refusal to rename over an existing file; changed callers. Bug and fix from + + 4/8 + --- +builtins/trap.def + - display_traps,showtrap: take an additional int argument, that, if + non-zero, means to print a trap command for a signal whose disposition + is SIG_DFL + - trap_builtin: if the -p option is given, and posix mode is enabled, + pass the `show every signal' flag to display_traps so SIG_DFL signals + are displayed as `trap -- - '. From an austin-group + interpretation (1212) initiated by Robert Elz . + Tagged for bash-5.1 + + 4/9 + --- +jobs.c + - list_one_job: printing one job counts as notifying the user about + it, so add a call to cleanup_dead_jobs like in the other job display + functions. Fixes https://savannah.gnu.org/support/?109667 reported + by "Brian K. White" + + 4/10 + ---- +redir.c + - HEREDOC_PIPESIZE: define to PIPESIZE if not defined, allow it to be + specified at build time; used in here_document_to_fd to determine + whether or not a pipe is used + - HEREDOC_PIPEMAX: allow build-time definition of the max heredoc size + that will be written to a pipe + - here_document_to_fd: if F_GETPIPE_SZ is defined (Linux), ensure that + the document is shorter than the possibly-dynamic max pipe size, + and fall back to the tempfile implementation if it is not + - HEREDOC_PARANOID: if this is defined to a non-zero value, + here_document_to_fd ensures that both file descriptors opened on + the temporary file refer to the same file + +lib/sh/zmapfd.c + - zmapfd: increased the default allocation sizes + +lib/sh/zcatfd.c + - zcatfd: increased the default allocation sizes + +input.c + - localbuf: increased the default buffer size for reads + + 4/11 + ---- +subst.c + - cond_expand_word: like expand_word_unsplit, we need to peform + quoted null character removal on both the LHS and RHS of the + operator, since we are not performing word splitting. Fixes bug + reported by Matt Whitlock in https://savannah.gnu.org/support/?109671 + + 4/12 + ---- +jobs.c + - wait_for_background_pids: don't bother with the loop that waits for + and reaps all children of the shell in the case that it's inherited + some children it doesn't care about. Report from Daniel Kahn Gillmor + + + 4/14 + ---- +subst.c + - command_substitute: add an unwind-protect to make sure the read end + of the pipe gets closed in the parent on a SIGINT that interrupts + the zread. Fixes fast SIGINT fd leak reported by Tycho Kirchner + + +bashhist.c + - history_number: if enable_history_list is set (`set -o history' has + been executed), return the current history number even if we're + not currently saving commands in the history list + (remember_on_history == 0). Prompted by report from Paul Wise + diff --git a/bashhist.c b/bashhist.c index 710372b2..ed16d7a7 100644 --- a/bashhist.c +++ b/bashhist.c @@ -1,6 +1,6 @@ /* bashhist.c -- bash interface to the GNU history library. */ -/* Copyright (C) 1993-2015 Free Software Foundation, Inc. +/* Copyright (C) 1993-2019 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -943,7 +943,7 @@ int history_number () { using_history (); - return (remember_on_history ? history_base + where_history () : 1); + return ((remember_on_history || enable_history_list) ? history_base + where_history () : 1); } static int diff --git a/builtins/trap.def b/builtins/trap.def index 09846981..2848b776 100644 --- a/builtins/trap.def +++ b/builtins/trap.def @@ -1,7 +1,7 @@ This file is trap.def, from which is created trap.c. It implements the builtin "trap" in Bash. -Copyright (C) 1987-2015 Free Software Foundation, Inc. +Copyright (C) 1987-2019 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -75,8 +75,8 @@ $END #include "common.h" #include "bashgetopt.h" -static void showtrap __P((int)); -static int display_traps __P((WORD_LIST *)); +static void showtrap __P((int, int)); +static int display_traps __P((WORD_LIST *, int)); /* The trap command: @@ -133,7 +133,11 @@ trap_builtin (list) { initialize_terminating_signals (); get_all_original_signals (); - return (sh_chkwrite (display_traps (list))); +#if 0 /* TAG:bash-5.1 */ + return (sh_chkwrite (display_traps (list, display && posixly_correct))); +#else + return (sh_chkwrite (display_traps (list, 0))); +#endif } else { @@ -246,14 +250,19 @@ trap_builtin (list) } static void -showtrap (i) - int i; +showtrap (i, show_default) + int i, show_default; { char *t, *p, *sn; p = trap_list[i]; if (p == (char *)DEFAULT_SIG && signal_is_hard_ignored (i) == 0) - return; + { + if (show_default) + t = "-"; + else + return; + } else if (signal_is_hard_ignored (i)) t = (char *)NULL; else @@ -274,19 +283,21 @@ showtrap (i) else printf ("trap -- %s %s\n", t ? t : "''", sn); - FREE (t); + if (show_default == 0) + FREE (t); } static int -display_traps (list) +display_traps (list, show_all) WORD_LIST *list; + int show_all; { int result, i; if (list == 0) { for (i = 0; i < BASH_NSIG; i++) - showtrap (i); + showtrap (i, show_all); return (EXECUTION_SUCCESS); } @@ -299,7 +310,7 @@ display_traps (list) result = EXECUTION_FAILURE; } else - showtrap (i); + showtrap (i, show_all); } return (result); diff --git a/doc/version.texi b/doc/version.texi index b98da094..aad2600d 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -2,10 +2,10 @@ Copyright (C) 1988-2019 Free Software Foundation, Inc. @end ignore -@set LASTCHANGE Sun Mar 24 14:05:55 EDT 2019 +@set LASTCHANGE Fri Apr 12 16:27:08 EDT 2019 @set EDITION 5.0 @set VERSION 5.0 -@set UPDATED 24 March 2019 -@set UPDATED-MONTH March 2019 +@set UPDATED 12 April 2019 +@set UPDATED-MONTH April 2019 diff --git a/input.c b/input.c index 8b3e4259..c5192a24 100644 --- a/input.c +++ b/input.c @@ -62,7 +62,7 @@ extern void termsig_handler __P((int)); /* Functions to handle reading input on systems that don't restart read(2) if a signal is received. */ -static char localbuf[128]; +static char localbuf[1024]; static int local_index = 0, local_bufused = 0; /* Posix and USG systems do not guarantee to restart read () if it is diff --git a/jobs.c b/jobs.c index fae63f07..380704cc 100644 --- a/jobs.c +++ b/jobs.c @@ -1885,6 +1885,7 @@ list_one_job (job, format, ignore, job_index) int format, ignore, job_index; { pretty_print_job (job_index, format, stdout); + cleanup_dead_jobs (); } void @@ -2488,10 +2489,8 @@ wait_for_background_pids () r = wait_for (last_procsub_child->pid); wait_procsubs (); reap_procsubs (); -#if 1 +#if 0 /* We don't want to wait indefinitely if we have stopped children. */ - /* XXX - should add a loop that goes through the list of process - substitutions and waits for each proc in turn before this code. */ if (any_stopped == 0) { /* Check whether or not we have any unreaped children. */ diff --git a/lib/glob/glob.c b/lib/glob/glob.c index 50c263da..c69d9489 100644 --- a/lib/glob/glob.c +++ b/lib/glob/glob.c @@ -823,6 +823,7 @@ glob_vector (pat, dir, flags) } } +#if 0 /* When FLAGS includes GX_ALLDIRS, we want to skip a symlink to a directory, since we will pick the directory up later. */ if (isdir == -2 && glob_testdir (subdir, 0) == 0) @@ -830,6 +831,7 @@ glob_vector (pat, dir, flags) free (subdir); continue; } +#endif /* XXX - should we even add this if it's not a directory? */ nextlink = (struct globval *) malloc (sizeof (struct globval)); diff --git a/lib/readline/doc/rluser.texi b/lib/readline/doc/rluser.texi index bbe41e1e..e8cb9a45 100644 --- a/lib/readline/doc/rluser.texi +++ b/lib/readline/doc/rluser.texi @@ -2380,7 +2380,7 @@ Many more examples -- an extensive collection of completions for most of the common GNU, Unix, and Linux commands -- are available as part of the bash_completion project. This is installed by default on many GNU/Linux distributions. Originally written by Ian Macdonald, the project now lives -at @url{http://bash-completion.alioth.debian.org/}. There are ports for +at @url{https://salsa.debian.org/debian/bash-completion}. There are ports for other systems such as Solaris and Mac OS X. An older version of the bash_completion package is distributed with bash diff --git a/lib/sh/zcatfd.c b/lib/sh/zcatfd.c index bdbcd910..b0efc940 100644 --- a/lib/sh/zcatfd.c +++ b/lib/sh/zcatfd.c @@ -46,7 +46,7 @@ zcatfd (fd, ofd, fn) { ssize_t nr; int rval; - char lbuf[128]; + char lbuf[1024]; rval = 0; while (1) diff --git a/lib/sh/zmapfd.c b/lib/sh/zmapfd.c index e7208921..c5544e67 100644 --- a/lib/sh/zmapfd.c +++ b/lib/sh/zmapfd.c @@ -48,12 +48,12 @@ zmapfd (fd, ostr, fn) { ssize_t nr; int rval; - char lbuf[128]; + char lbuf[512]; char *result; int rsize, rind; rval = 0; - result = (char *)xmalloc (rsize = 64); + result = (char *)xmalloc (rsize = 512); rind = 0; while (1) @@ -72,7 +72,7 @@ zmapfd (fd, ostr, fn) return -1; } - RESIZE_MALLOCED_BUFFER (result, rind, nr, rsize, 128); + RESIZE_MALLOCED_BUFFER (result, rind, nr, rsize, 512); memcpy (result+rind, lbuf, nr); rind += nr; } diff --git a/redir.c b/redir.c index 40ea6f2d..6f4e600b 100644 --- a/redir.c +++ b/redir.c @@ -69,6 +69,16 @@ extern int errno; # endif #endif +#ifndef HEREDOC_PIPESIZE +# define HEREDOC_PIPESIZE PIPESIZE +#endif + +#if defined (HEREDOC_PIPEMAX) +# if HEREDOC_PIPESIZE > HEREDOC_PIPEMAX +# define HEREDOC_PIPESIZE HEREDOC_PIPEMAX +# endif +#endif + #define SHELL_FD_BASE 10 int expanding_redir; @@ -418,6 +428,9 @@ here_document_to_fd (redirectee, ri) int r, fd, fd2, herepipe[2]; char *document; size_t document_len; +#if HEREDOC_PARANOID + struct stat st1, st2; +#endif /* Expand the here-document/here-string first and then decide what to do. */ document = heredoc_expand (redirectee, ri, &document_len); @@ -433,11 +446,11 @@ here_document_to_fd (redirectee, ri) return fd; } -#if defined (PIPESIZE) +#if defined (HEREDOC_PIPESIZE) /* Try to use a pipe internal to this process if the document is shorter than the system's pipe capacity (computed at build time). We want to write the entire document without write blocking. */ - if (document_len <= PIPESIZE) + if (document_len <= HEREDOC_PIPESIZE) { if (pipe (herepipe) < 0) { @@ -447,6 +460,12 @@ here_document_to_fd (redirectee, ri) errno = r; return (-1); } + +#if defined (F_GETPIPE_SZ) + if (fcntl (herepipe[1], F_GETPIPE_SZ, 0) < document_len) + goto use_tempfile; +#endif + r = heredoc_write (herepipe[1], document, document_len); if (document != redirectee->word) free (document); @@ -461,6 +480,8 @@ here_document_to_fd (redirectee, ri) } #endif +use_tempfile: + fd = sh_mktmpfd ("sh-thd", MT_USERANDOM|MT_USETMPDIR, &filename); /* If we failed for some reason other than the file existing, abort */ @@ -506,6 +527,22 @@ here_document_to_fd (redirectee, ri) return -1; } +#if HEREDOC_PARANOID + /* We can use same_file here to check whether or not fd and fd2 refer to + the same file, but we don't do that unless HEREDOC_PARANOID is defined. */ + if (fstat (fd, &st1) < 0 || S_ISREG (st1.st_mode) == 0 || + fstat (fd2, &st2) < 0 || S_ISREG (st2.st_mode) == 0 || + same_file (filename, filename, &st1, &st2) == 0) + { + unlink (filename); + free (filename); + close (fd); + close (fd2); + errno = EEXIST; + return -1; + } +#endif + close (fd); if (unlink (filename) < 0) { diff --git a/subst.c b/subst.c index 47d9dbc8..3a70d725 100644 --- a/subst.c +++ b/subst.c @@ -3641,7 +3641,9 @@ remove_backslashes (string) this case, we quote the string specially for the globbing code. If SPECIAL is 2, this is an rhs argument for the =~ operator, and should be quoted appropriately for regcomp/regexec. The caller is responsible - for removing the backslashes if the unquoted word is needed later. */ + for removing the backslashes if the unquoted word is needed later. In + any case, since we don't perform word splitting, we need to do quoted + null character removal. */ char * cond_expand_word (w, special) WORD_DESC *w; @@ -3662,6 +3664,8 @@ cond_expand_word (w, special) { if (special == 0) /* LHS */ { + if (l->word) + word_list_remove_quoted_nulls (l); dequote_list (l); r = string_list (l); } @@ -6414,16 +6418,23 @@ command_substitute (string, quoted, flags) } else { + int dummyfd; + #if defined (JOB_CONTROL) && defined (PGRP_PIPE) close_pgrp_pipe (); #endif /* JOB_CONTROL && PGRP_PIPE */ close (fildes[1]); + begin_unwind_frame ("read-comsub"); + dummyfd = fildes[0]; + add_unwind_protect (close, dummyfd); + tflag = 0; istring = read_comsub (fildes[0], quoted, flags, &tflag); close (fildes[0]); + discard_unwind_frame ("read-comsub"); current_command_subst_pid = pid; last_command_exit_value = wait_for (pid);