Bash patch catchup including shellshock oi_151a tip
authorJon Tibble <meths@btinternet.com>
Mon, 04 May 2015 14:04:39 +0100
branchoi_151a
changeset 254 9c2a4ac793f0
parent 253 702bbe36863b
Bash patch catchup including shellshock
usr/src/cmd/bash/Patches-4.0/bash40-029
usr/src/cmd/bash/Patches-4.0/bash40-030
usr/src/cmd/bash/Patches-4.0/bash40-031
usr/src/cmd/bash/Patches-4.0/bash40-032
usr/src/cmd/bash/Patches-4.0/bash40-033
usr/src/cmd/bash/Patches-4.0/bash40-034
usr/src/cmd/bash/Patches-4.0/bash40-035
usr/src/cmd/bash/Patches-4.0/bash40-036
usr/src/cmd/bash/Patches-4.0/bash40-037
usr/src/cmd/bash/Patches-4.0/bash40-038
usr/src/cmd/bash/Patches-4.0/bash40-039
usr/src/cmd/bash/Patches-4.0/bash40-040
usr/src/cmd/bash/Patches-4.0/bash40-041
usr/src/cmd/bash/Patches-4.0/bash40-042
usr/src/cmd/bash/Patches-4.0/bash40-043
usr/src/cmd/bash/Patches-4.0/bash40-044
usr/src/cmd/bash/Patches-4.0/disable-function-imports
usr/src/cmd/bash/Solaris/apply_patches.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-029	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,106 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release: 4.0
+Patch-ID: bash40-029
+
+Bug-Reported-by:	Christian Krause <[email protected]>
+Bug-Reference-ID:	Thu, 25 Jun 2009 21:47:59 +0200
+Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2009-06/msg00078.html
+
+Bug-Description:
+
+Previous versions of bash accepted strings in the initial environment
+that were not valid shell variable assignments, usually because the
+names were invalid, but still created shell variables from them and
+passed them to child processes in the environment.
+
+Bash-4.0 ignores those names and does not pass them to child processes.
+Some users and automated processes depend on invalid variables being
+ignored and passed to child processes.
+
+This patch makes bash continue to ignore the invalid names, but pass
+them to child processes in the export environment.
+
+Patch:
+
+*** ../bash-4.0-patched/variables.c	2009-01-04 14:32:46.000000000 -0500
+--- variables.c	2009-06-29 09:17:20.000000000 -0400
+***************
+*** 253,256 ****
+--- 255,259 ----
+  static int visible_var __P((SHELL_VAR *));
+  static int visible_and_exported __P((SHELL_VAR *));
++ static int export_environment_candidate __P((SHELL_VAR *));
+  static int local_and_exported __P((SHELL_VAR *));
+  static int variable_in_context __P((SHELL_VAR *));
+***************
+*** 376,383 ****
+  #  endif
+  #endif
+        else if (legal_identifier (name))
+  	{
+  	  temp_var = bind_variable (name, string, 0);
+! 	  VSETATTR (temp_var, (att_exported | att_imported));
+  	  array_needs_making = 1;
+  	}
+--- 379,393 ----
+  #  endif
+  #endif
++ #if 0
+        else if (legal_identifier (name))
++ #else
++       else
++ #endif
+  	{
+  	  temp_var = bind_variable (name, string, 0);
+! 	  if (legal_identifier (name))
+! 	    VSETATTR (temp_var, (att_exported | att_imported));
+! 	  else
+! 	    VSETATTR (temp_var, (att_exported | att_imported | att_invisible));
+  	  array_needs_making = 1;
+  	}
+***************
+*** 3083,3086 ****
+--- 3098,3111 ----
+  }
+  
++ /* Candidate variables for the export environment are either valid variables
++    with the export attribute or invalid variables inherited from the initial
++    environment and simply passed through. */
++ static int
++ export_environment_candidate (var)
++      SHELL_VAR *var;
++ {
++   return (exported_p (var) && (invisible_p (var) == 0 || imported_p (var)));
++ }
++ 
+  /* Return non-zero if VAR is a local variable in the current context and
+     is exported. */
+***************
+*** 3439,3443 ****
+--- 3464,3472 ----
+    SHELL_VAR **vars;
+  
++ #if 0
+    vars = map_over (visible_and_exported, vcxt);
++ #else
++   vars = map_over (export_environment_candidate, vcxt);
++ #endif
+  
+    if (vars == 0)
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 28
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 29
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-030	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,64 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release: 4.0
+Patch-ID: bash40-030
+
+Bug-Reported-by:	Henning Bekel <[email protected]>
+Bug-Reference-ID:	<[email protected]>
+Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2009-07/msg00054.html
+
+Bug-Description:
+
+A shell function invoked with `bind -x' is supposed to be able to move the
+cursor by setting READLINE_POINT.  The effects of this assignment were
+sometimes ignored.
+
+Patch:
+
+*** ../bash-4.0-patched/bashline.c	2009-01-08 09:29:24.000000000 -0500
+--- bashline.c	2009-07-16 14:13:41.000000000 -0400
+***************
+*** 3389,3393 ****
+    register int i;
+    intmax_t mi;
+-   int save_point;
+    sh_parser_state_t ps;
+    char *cmd, *value, *l;
+--- 3389,3392 ----
+***************
+*** 3433,3437 ****
+      VSETATTR (v, att_exported);
+    l = value_cell (v);
+-   save_point = rl_point;
+    value = inttostr (rl_point, ibuf, sizeof (ibuf));
+    v = bind_int_variable ("READLINE_POINT", value);
+--- 3432,3435 ----
+***************
+*** 3451,3455 ****
+      {
+        i = mi;
+!       if (i != save_point)
+  	{
+  	  rl_point = i;
+--- 3449,3453 ----
+      {
+        i = mi;
+!       if (i != rl_point)
+  	{
+  	  rl_point = i;
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 29
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 30
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-031	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,62 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release: 4.0
+Patch-ID: bash40-031
+
+Bug-Reported-by:	Roman Rakus <[email protected]>
+Bug-Reference-ID:	<[email protected]>
+Bug-Reference-URL:	
+
+Bug-Description:
+
+An implicit assignment to index "0" of an existing array variable caused
+the shell to crash when the variable was unset.
+
+Patch:
+
+*** ../bash-4.0-patched/arrayfunc.c	2009-03-08 21:24:39.000000000 -0400
+--- arrayfunc.c	2009-08-24 09:29:43.000000000 -0400
+***************
+*** 99,103 ****
+    hash = assoc_create (0);
+    if (oldval)
+!     assoc_insert (hash, "0", oldval);
+  
+    FREE (value_cell (var));
+--- 99,103 ----
+    hash = assoc_create (0);
+    if (oldval)
+!     assoc_insert (hash, savestring ("0"), oldval);
+  
+    FREE (value_cell (var));
+*** ../bash-4.0-patched/variables.c	2009-01-04 14:32:46.000000000 -0500
+--- variables.c	2009-08-24 09:29:58.000000000 -0400
+***************
+*** 2218,2222 ****
+        else if (assoc_p (entry))
+  	{
+! 	  assoc_insert (assoc_cell (entry), "0", newval);
+  	  free (newval);
+  	}
+--- 2218,2222 ----
+        else if (assoc_p (entry))
+  	{
+! 	  assoc_insert (assoc_cell (entry), savestring ("0"), newval);
+  	  free (newval);
+  	}
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 30
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 31
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-032	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,46 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release: 4.0
+Patch-ID: bash40-032
+
+Bug-Reported-by:	[email protected]
+Bug-Reference-ID:	<[email protected]>
+Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2009-08/msg00090.html
+
+Bug-Description:
+
+Bash-4.0 has a memory leak when processing ${!prefix@}.
+
+Patch:
+
+*** ../bash-4.0-patched/subst.c	2009-07-22 23:18:55.000000000 -0400
+--- subst.c	2009-08-26 23:08:51.000000000 -0400
+***************
+*** 6607,6611 ****
+  	}
+        free (x);
+!       free (xlist);
+        free (temp1);
+        *indexp = sindex;
+--- 6769,6773 ----
+  	}
+        free (x);
+!       dispose_words (xlist);
+        free (temp1);
+        *indexp = sindex;
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 31
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 32
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-033	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,50 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release: 4.0
+Patch-ID: bash40-033
+
+Bug-Reported-by:	Dr. Werner Fink <[email protected]>
+Bug-Reference-ID:	<[email protected]>
+Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2009-07/msg00000.html
+
+Bug-Description:
+
+Bash-4.0 has a memory leak in the `read' builtin when the number of fields
+read is not the same as the number of variables passed as arguments.
+
+Patch:
+
+*** ../bash-4.0-patched/builtins/read.def	2009-03-08 21:24:45.000000000 -0400
+--- builtins/read.def	2009-07-01 15:32:42.000000000 -0400
+***************
+*** 764,768 ****
+  	tofree = input_string = t;
+        else
+! 	input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape);
+      }
+  #endif
+--- 764,771 ----
+  	tofree = input_string = t;
+        else
+! 	{
+! 	  input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape);
+! 	  tofree = t;
+! 	}
+      }
+  #endif
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 32
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 33
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-034	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,59 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release:	4.0
+Patch-ID:	bash40-034
+
+Bug-Reported-by:	Anders Kaseorg <[email protected]>
+Bug-Reference-ID:	<[email protected]>
+Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2009-09/msg00043.html
+
+Bug-Description:
+
+When using the globstar option, bash incorrectly interprets wildcarded path
+components between a **/ and the last / as matching any path, even if the
+constructed path does not match any files.
+
+Patch:
+
+*** ../bash-4.0-patched/lib/glob/glob.c	2009-07-22 23:18:50.000000000 -0400
+--- lib/glob/glob.c	2009-09-18 17:53:25.000000000 -0400
+***************
+*** 920,928 ****
+  	  char **temp_results;
+  
+  	  /* Scan directory even on a NULL filename.  That way, `*h/'
+  	     returns only directories ending in `h', instead of all
+  	     files ending in `h' with a `/' appended. */
+  	  dname = directories[i];
+! 	  dflags = flags & ~GX_MARKDIRS;
+  	  if ((flags & GX_GLOBSTAR) && filename[0] == '*' && filename[1] == '*' && filename[2] == '\0')
+  	    dflags |= GX_ALLDIRS|GX_ADDCURDIR;
+--- 927,938 ----
+  	  char **temp_results;
+  
++ 	  /* XXX -- we've recursively scanned any directories resulting from
++ 	     a `**', so turn off the flag.  We turn it on again below if
++ 	     filename is `**' */
+  	  /* Scan directory even on a NULL filename.  That way, `*h/'
+  	     returns only directories ending in `h', instead of all
+  	     files ending in `h' with a `/' appended. */
+  	  dname = directories[i];
+! 	  dflags = flags & ~(GX_MARKDIRS|GX_ALLDIRS|GX_ADDCURDIR);
+  	  if ((flags & GX_GLOBSTAR) && filename[0] == '*' && filename[1] == '*' && filename[2] == '\0')
+  	    dflags |= GX_ALLDIRS|GX_ADDCURDIR;
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 33
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 34
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-035	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,62 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release:	4.0
+Patch-ID:	bash40-035
+
+Bug-Reported-by:	Freddy Vulto <[email protected]>
+Bug-Reference-ID:	<[email protected]>
+Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2009-09/msg00044.html
+
+Bug-Description:
+
+Bash-4.0 incorrectly treated single and double quotes as delimiters rather
+than introducing quoted strings when splitting the line into words for
+programmable completion functions.
+
+Patch:
+
+*** ../bash-4.0-patched/pcomplete.c	2009-03-08 21:24:31.000000000 -0400
+--- pcomplete.c	2009-09-26 16:30:16.000000000 -0400
+***************
+*** 1176,1186 ****
+    WORD_LIST *ret;
+    char *delims;
+  
+! #if 0
+!   delims = "()<>;&| \t\n";	/* shell metacharacters break words */
+! #else
+!   delims = rl_completer_word_break_characters;
+! #endif
+    ret = split_at_delims (line, llen, delims, sentinel, nwp, cwp);
+    return (ret);
+  }
+--- 1176,1188 ----
+    WORD_LIST *ret;
+    char *delims;
++   int i, j;
+  
+!   delims = xmalloc (strlen (rl_completer_word_break_characters) + 1);
+!   for (i = j = 0; rl_completer_word_break_characters[i]; i++)
+!     if (rl_completer_word_break_characters[i] != '\'' && rl_completer_word_break_characters[i] != '"')
+!       delims[j++] = rl_completer_word_break_characters[i];
+!   delims[j] = '\0';
+    ret = split_at_delims (line, llen, delims, sentinel, nwp, cwp);
++   free (delims);
+    return (ret);
+  }
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 34
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 35
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-036	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,90 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release: 4.0
+Patch-ID: bash40-036
+
+Bug-Reported-by:	Jerome Reybert <[email protected]>
+Bug-Reference-ID:	<[email protected]>
+Bug-Reference-URL:	http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=538013
+
+Bug-Description:
+
+Under some circumstances, menu-complete is unable to complete filenames.
+
+Patch:
+
+*** ../bash-4.0-patched/lib/readline/complete.c	2009-01-22 15:15:14.000000000 -0500
+--- lib/readline/complete.c	2009-08-26 17:15:59.000000000 -0400
+***************
+*** 2209,2213 ****
+    /* The first time through, we generate the list of matches and set things
+       up to insert them. */
+!   if (rl_last_func != rl_menu_complete)
+      {
+        /* Clean up from previous call, if any. */
+--- 2252,2256 ----
+    /* The first time through, we generate the list of matches and set things
+       up to insert them. */
+!   if (rl_last_func != rl_old_menu_complete)
+      {
+        /* Clean up from previous call, if any. */
+***************
+*** 2221,2224 ****
+--- 2264,2269 ----
+        rl_completion_invoking_key = invoking_key;
+  
++       RL_SETSTATE(RL_STATE_COMPLETING);
++ 
+        /* Only the completion entry function can change these. */
+        set_completion_defaults ('%');
+***************
+*** 2260,2266 ****
+--- 2305,2314 ----
+  	  orig_text = (char *)0;
+      	  completion_changed_buffer = 0;
++  	  RL_UNSETSTATE(RL_STATE_COMPLETING);
+            return (0);
+  	}
+  
++       RL_UNSETSTATE(RL_STATE_COMPLETING);
++ 
+        for (match_list_size = 0; matches[match_list_size]; match_list_size++)
+          ;
+***************
+*** 2338,2341 ****
+--- 2386,2391 ----
+        full_completion = 0;
+  
++       RL_SETSTATE(RL_STATE_COMPLETING);
++ 
+        /* Only the completion entry function can change these. */
+        set_completion_defaults ('%');
+***************
+*** 2379,2385 ****
+--- 2429,2438 ----
+  	  orig_text = (char *)0;
+      	  completion_changed_buffer = 0;
++  	  RL_UNSETSTATE(RL_STATE_COMPLETING);
+            return (0);
+  	}
+  
++       RL_UNSETSTATE(RL_STATE_COMPLETING);
++ 
+        for (match_list_size = 0; matches[match_list_size]; match_list_size++)
+          ;
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 35
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 36
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-037	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,60 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release: 4.0
+Patch-ID: bash40-037
+
+Bug-Reported-by:	Chet Ramey <[email protected]>
+Bug-Reference-ID:	<[email protected]>
+Bug-Reference-URL:
+
+Bug-Description:
+
+The configure script does not work on Snow Leopard and will result in
+attempts to link against the incorrect version of readline.
+
+Patch:
+
+*** ../bash-4.0-patched/configure.in	2009-02-06 12:03:44.000000000 -0500
+--- configure.in	2009-10-01 16:38:24.000000000 -0400
+***************
+*** 534,538 ****
+  		# dynamic version
+  		case "${host_os}" in
+! 		darwin[[89]]*)	READLINE_LIB='${READLINE_LIBRARY}' ;;
+  		*)		READLINE_LIB=-lreadline ;;
+  		esac
+--- 534,538 ----
+  		# dynamic version
+  		case "${host_os}" in
+! 		darwin[[89]]*|darwin10*) READLINE_LIB='${READLINE_LIBRARY}' ;;
+  		*)		READLINE_LIB=-lreadline ;;
+  		esac
+***************
+*** 569,573 ****
+  		# dynamic version
+  		case "${host_os}" in
+! 		darwin[[89]]*)	HISTORY_LIB='${HISTORY_LIBRARY}' ;;
+  		*)		HISTORY_LIB=-lhistory ;;
+  		esac
+--- 569,573 ----
+  		# dynamic version
+  		case "${host_os}" in
+! 		darwin[[89]]*|darwin10*) HISTORY_LIB='${HISTORY_LIBRARY}' ;;
+  		*)		HISTORY_LIB=-lhistory ;;
+  		esac
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 36
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 37
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-038	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,56 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release:	4.0
+Patch-ID:	bash40-038
+
+Bug-Reported-by:	[email protected]
+Bug-Reference-ID:	<[email protected]>
+Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2010-02/msg00132.html
+
+Bug-Description:
+
+When the `read' builtin times out after the timeout specified with -t is
+exceeded, it does not reset the flags that tell signal handlers to process
+signals immediately instead of deferring their handling.  This can result
+in unsafe functions being called from signal handlers, which can cause bash
+to hang or dump core.
+
+Patch (apply with `patch -p0'):
+
+*** ../bash-4.0-patched/builtins/read.def	2009-09-03 14:40:03.000000000 -0400
+--- builtins/read.def	2010-03-17 17:35:39.000000000 -0400
+***************
+*** 602,607 ****
+      zsyncfd (fd);
+  
+-   interrupt_immediately--;
+-   terminate_immediately--;
+    discard_unwind_frame ("read_builtin");
+  
+--- 616,619 ----
+***************
+*** 610,613 ****
+--- 622,628 ----
+  assign_vars:
+  
++   interrupt_immediately--;
++   terminate_immediately--;
++ 
+  #if defined (ARRAY_VARS)
+    /* If -a was given, take the string read, break it into a list of words,
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 37
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 38
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-039	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,104 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release:	4.0
+Patch-ID:	bash40-039
+
+Bug-Reported-by:	Stephane Chazelas <[email protected]>
+Bug-Reference-ID:
+Bug-Reference-URL:
+
+Bug-Description:
+
+Under certain circumstances, bash will execute user code while processing the
+environment for exported function definitions.
+
+Patch (apply with `patch -p0'):
+
+*** ../bash-4.0.38/builtins/common.h	2009-01-15 23:08:54.000000000 -0500
+--- builtins/common.h	2014-09-16 19:20:48.000000000 -0400
+***************
+*** 36,39 ****
+--- 36,41 ----
+  
+  /* Flags for describe_command, shared between type.def and command.def */
++ #define SEVAL_FUNCDEF	0x080		/* only allow function definitions */
++ #define SEVAL_ONECMD	0x100		/* only allow a single command */
+  #define CDESC_ALL		0x001	/* type -a */
+  #define CDESC_SHORTDESC		0x002	/* command -V */
+*** ../bash-4.0.38/builtins/evalstring.c	2009-01-13 14:44:12.000000000 -0500
+--- builtins/evalstring.c	2014-09-16 19:20:48.000000000 -0400
+***************
+*** 259,262 ****
+--- 259,270 ----
+  	      struct fd_bitmap *bitmap;
+  
++ 	      if ((flags & SEVAL_FUNCDEF) && command->type != cm_function_def)
++ 		{
++ 		  internal_warning ("%s: ignoring function definition attempt", from_file);
++ 		  should_jump_to_top_level = 0;
++ 		  last_result = last_command_exit_value = EX_BADUSAGE;
++ 		  break;
++ 		}
++ 
+  	      bitmap = new_fd_bitmap (FD_BITMAP_SIZE);
+  	      begin_unwind_frame ("pe_dispose");
+***************
+*** 319,322 ****
+--- 327,333 ----
+  	      dispose_fd_bitmap (bitmap);
+  	      discard_unwind_frame ("pe_dispose");
++ 
++ 	      if (flags & SEVAL_ONECMD)
++ 		break;
+  	    }
+  	}
+*** ../bash-4.0.38/variables.c	2009-09-19 13:04:23.000000000 -0400
+--- variables.c	2014-09-16 19:20:48.000000000 -0400
+***************
+*** 344,353 ****
+  	  strcpy (temp_string + char_index + 1, string);
+  
+! 	  parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST);
+! 
+! 	  /* Ancient backwards compatibility.  Old versions of bash exported
+! 	     functions like name()=() {...} */
+! 	  if (name[char_index - 1] == ')' && name[char_index - 2] == '(')
+! 	    name[char_index - 2] = '\0';
+  
+  	  if (temp_var = find_function (name))
+--- 344,351 ----
+  	  strcpy (temp_string + char_index + 1, string);
+  
+! 	  /* Don't import function names that are invalid identifiers from the
+! 	     environment. */
+! 	  if (legal_identifier (name))
+! 	    parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
+  
+  	  if (temp_var = find_function (name))
+***************
+*** 358,365 ****
+  	  else
+  	    report_error (_("error importing function definition for `%s'"), name);
+- 
+- 	  /* ( */
+- 	  if (name[char_index - 1] == ')' && name[char_index - 2] == '\0')
+- 	    name[char_index - 2] = '(';		/* ) */
+  	}
+  #if defined (ARRAY_VARS)
+--- 356,359 ----
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 38
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 39
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-040	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,43 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release:	4.0
+Patch-ID:	bash40-040
+
+Bug-Reported-by:	Tavis Ormandy <[email protected]>
+Bug-Reference-ID:
+Bug-Reference-URL:	http://twitter.com/taviso/statuses/514887394294652929
+
+Bug-Description:
+
+Under certain circumstances, bash can incorrectly save a lookahead character and
+return it on a subsequent call, even when reading a new line.
+
+Patch (apply with `patch -p0'):
+
+*** ../bash-4.0.39/parse.y	2009-06-02 09:08:07.000000000 -0400
+--- parse.y	2014-09-25 16:15:47.000000000 -0400
+***************
+*** 2671,2674 ****
+--- 2671,2676 ----
+    word_desc_to_read = (WORD_DESC *)NULL;
+  
++   eol_ungetc_lookahead = 0;
++ 
+    current_token = '\n';		/* XXX */
+    last_read_token = '\n';
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 39
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 40
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-041	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,217 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release: 4.0
+Patch-ID: bash40-041
+
+Bug-Reported-by:	Florian Weimer <[email protected]>
+Bug-Reference-ID:
+Bug-Reference-URL:
+
+Bug-Description:
+
+This patch changes the encoding bash uses for exported functions to avoid
+clashes with shell variables and to avoid depending only on an environment
+variable's contents to determine whether or not to interpret it as a shell
+function.
+
+Patch:
+
+*** ../bash-4.0.40/variables.c	2014-09-16 19:20:48.000000000 -0400
+--- variables.c	2014-09-27 21:01:42.000000000 -0400
+***************
+*** 78,81 ****
+--- 78,86 ----
+  #define ifsname(s)	((s)[0] == 'I' && (s)[1] == 'F' && (s)[2] == 'S' && (s)[3] == '\0')
+  
++ #define BASHFUNC_PREFIX		"BASH_FUNC_"
++ #define BASHFUNC_PREFLEN	10	/* == strlen(BASHFUNC_PREFIX */
++ #define BASHFUNC_SUFFIX		"%%"
++ #define BASHFUNC_SUFFLEN	2	/* == strlen(BASHFUNC_SUFFIX) */
++ 
+  extern char **environ;
+  
+***************
+*** 265,269 ****
+  static void dispose_temporary_env __P((sh_free_func_t *));     
+  
+! static inline char *mk_env_string __P((const char *, const char *));
+  static char **make_env_array_from_var_list __P((SHELL_VAR **));
+  static char **make_var_export_array __P((VAR_CONTEXT *));
+--- 270,274 ----
+  static void dispose_temporary_env __P((sh_free_func_t *));     
+  
+! static inline char *mk_env_string __P((const char *, const char *, int));
+  static char **make_env_array_from_var_list __P((SHELL_VAR **));
+  static char **make_var_export_array __P((VAR_CONTEXT *));
+***************
+*** 335,353 ****
+        /* If exported function, define it now.  Don't import functions from
+  	 the environment in privileged mode. */
+!       if (privmode == 0 && read_but_dont_execute == 0 && STREQN ("() {", string, 4))
+  	{
+  	  string_length = strlen (string);
+! 	  temp_string = (char *)xmalloc (3 + string_length + char_index);
+  
+! 	  strcpy (temp_string, name);
+! 	  temp_string[char_index] = ' ';
+! 	  strcpy (temp_string + char_index + 1, string);
+  
+  	  /* Don't import function names that are invalid identifiers from the
+  	     environment. */
+! 	  if (legal_identifier (name))
+! 	    parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
+  
+! 	  if (temp_var = find_function (name))
+  	    {
+  	      VSETATTR (temp_var, (att_exported|att_imported));
+--- 340,369 ----
+        /* If exported function, define it now.  Don't import functions from
+  	 the environment in privileged mode. */
+!       if (privmode == 0 && read_but_dont_execute == 0 &&
+! 	  STREQN (BASHFUNC_PREFIX, name, BASHFUNC_PREFLEN) &&
+! 	  STREQ (BASHFUNC_SUFFIX, name + char_index - BASHFUNC_SUFFLEN) &&
+! 	  STREQN ("() {", string, 4))
+  	{
++ 	  size_t namelen;
++ 	  char *tname;		/* desired imported function name */
++ 
++ 	  namelen = char_index - BASHFUNC_PREFLEN - BASHFUNC_SUFFLEN;
++ 
++ 	  tname = name + BASHFUNC_PREFLEN;	/* start of func name */
++ 	  tname[namelen] = '\0';		/* now tname == func name */
++ 
+  	  string_length = strlen (string);
+! 	  temp_string = (char *)xmalloc (namelen + string_length + 2);
+  
+! 	  memcpy (temp_string, tname, namelen);
+! 	  temp_string[namelen] = ' ';
+! 	  memcpy (temp_string + namelen + 1, string, string_length + 1);
+  
+  	  /* Don't import function names that are invalid identifiers from the
+  	     environment. */
+! 	  if (absolute_program (tname) == 0 && (posixly_correct == 0 || legal_identifier (tname)))
+! 	    parse_and_execute (temp_string, tname, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
+  
+! 	  if (temp_var = find_function (tname))
+  	    {
+  	      VSETATTR (temp_var, (att_exported|att_imported));
+***************
+*** 355,359 ****
+  	    }
+  	  else
+! 	    report_error (_("error importing function definition for `%s'"), name);
+  	}
+  #if defined (ARRAY_VARS)
+--- 371,378 ----
+  	    }
+  	  else
+! 	    report_error (_("error importing function definition for `%s'"), tname);
+! 
+! 	  /* Restore original suffix */
+! 	  tname[namelen] = BASHFUNC_SUFFIX[0];
+  	}
+  #if defined (ARRAY_VARS)
+***************
+*** 2506,2510 ****
+  
+    INVALIDATE_EXPORTSTR (var);
+!   var->exportstr = mk_env_string (name, value);
+  
+    array_needs_making = 1;
+--- 2525,2529 ----
+  
+    INVALIDATE_EXPORTSTR (var);
+!   var->exportstr = mk_env_string (name, value, 0);
+  
+    array_needs_making = 1;
+***************
+*** 3325,3343 ****
+  
+  static inline char *
+! mk_env_string (name, value)
+       const char *name, *value;
+  {
+!   int name_len, value_len;
+!   char	*p;
+  
+    name_len = strlen (name);
+    value_len = STRLEN (value);
+!   p = (char *)xmalloc (2 + name_len + value_len);
+!   strcpy (p, name);
+!   p[name_len] = '=';
+    if (value && *value)
+!     strcpy (p + name_len + 1, value);
+    else
+!     p[name_len + 1] = '\0';
+    return (p);
+  }
+--- 3344,3383 ----
+  
+  static inline char *
+! mk_env_string (name, value, isfunc)
+       const char *name, *value;
++      int isfunc;
+  {
+!   size_t name_len, value_len;
+!   char	*p, *q;
+  
+    name_len = strlen (name);
+    value_len = STRLEN (value);
+! 
+!   /* If we are exporting a shell function, construct the encoded function
+!      name. */
+!   if (isfunc && value)
+!     {
+!       p = (char *)xmalloc (BASHFUNC_PREFLEN + name_len + BASHFUNC_SUFFLEN + value_len + 2);
+!       q = p;
+!       memcpy (q, BASHFUNC_PREFIX, BASHFUNC_PREFLEN);
+!       q += BASHFUNC_PREFLEN;
+!       memcpy (q, name, name_len);
+!       q += name_len;
+!       memcpy (q, BASHFUNC_SUFFIX, BASHFUNC_SUFFLEN);
+!       q += BASHFUNC_SUFFLEN;
+!     }
+!   else
+!     {
+!       p = (char *)xmalloc (2 + name_len + value_len);
+!       memcpy (p, name, name_len);
+!       q = p + name_len;
+!     }
+! 
+!   q[0] = '=';
+    if (value && *value)
+!     memcpy (q + 1, value, value_len + 1);
+    else
+!     q[1] = '\0';
+! 
+    return (p);
+  }
+***************
+*** 3420,3424 ****
+  	     using the cached exportstr... */
+  	  list[list_index] = USE_EXPORTSTR ? savestring (value)
+! 					   : mk_env_string (var->name, value);
+  
+  	  if (USE_EXPORTSTR == 0)
+--- 3460,3464 ----
+  	     using the cached exportstr... */
+  	  list[list_index] = USE_EXPORTSTR ? savestring (value)
+! 					   : mk_env_string (var->name, value, function_p (var));
+  
+  	  if (USE_EXPORTSTR == 0)
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 40
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 41
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-042	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,147 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release: 4.0
+Patch-ID: bash40-042
+
+Bug-Reported-by:	Florian Weimer <[email protected]>
+Bug-Reference-ID:
+Bug-Reference-URL:
+
+Bug-Description:
+
+There are two local buffer overflows in parse.y that can cause the shell
+to dump core when given many here-documents attached to a single command
+or many nested loops.
+
+Patch:
+
+*** ../bash-4.0.41/parse.y	2014-09-27 12:17:56.000000000 -0400
+--- parse.y	2014-09-30 19:41:09.000000000 -0400
+***************
+*** 167,170 ****
+--- 167,173 ----
+  static int reserved_word_acceptable __P((int));
+  static int yylex __P((void));
++ 
++ static void push_heredoc __P((REDIRECT *));
++ static char *mk_alexpansion __P((char *));
+  static int alias_expand_token __P((char *));
+  static int time_command_acceptable __P((void));
+***************
+*** 262,266 ****
+  /* Variables to manage the task of reading here documents, because we need to
+     defer the reading until after a complete command has been collected. */
+! static REDIRECT *redir_stack[10];
+  int need_here_doc;
+  
+--- 265,271 ----
+  /* Variables to manage the task of reading here documents, because we need to
+     defer the reading until after a complete command has been collected. */
+! #define HEREDOC_MAX 16
+! 
+! static REDIRECT *redir_stack[HEREDOC_MAX];
+  int need_here_doc;
+  
+***************
+*** 301,305 ****
+     index is decremented after a case, select, or for command is parsed. */
+  #define MAX_CASE_NEST	128
+! static int word_lineno[MAX_CASE_NEST];
+  static int word_top = -1;
+  
+--- 306,310 ----
+     index is decremented after a case, select, or for command is parsed. */
+  #define MAX_CASE_NEST	128
+! static int word_lineno[MAX_CASE_NEST+1];
+  static int word_top = -1;
+  
+***************
+*** 452,456 ****
+  			  redir.filename = $2;
+  			  $$ = make_redirection (0, r_reading_until, redir);
+! 			  redir_stack[need_here_doc++] = $$;
+  			}
+  	|	NUMBER LESS_LESS WORD
+--- 457,461 ----
+  			  redir.filename = $2;
+  			  $$ = make_redirection (0, r_reading_until, redir);
+! 			  push_heredoc ($$);
+  			}
+  	|	NUMBER LESS_LESS WORD
+***************
+*** 458,462 ****
+  			  redir.filename = $3;
+  			  $$ = make_redirection ($1, r_reading_until, redir);
+! 			  redir_stack[need_here_doc++] = $$;
+  			}
+  	|	LESS_LESS_LESS WORD
+--- 463,467 ----
+  			  redir.filename = $3;
+  			  $$ = make_redirection ($1, r_reading_until, redir);
+! 			  push_heredoc ($$);
+  			}
+  	|	LESS_LESS_LESS WORD
+***************
+*** 515,519 ****
+  			  $$ = make_redirection
+  			    (0, r_deblank_reading_until, redir);
+! 			  redir_stack[need_here_doc++] = $$;
+  			}
+  	|	NUMBER LESS_LESS_MINUS WORD
+--- 520,524 ----
+  			  $$ = make_redirection
+  			    (0, r_deblank_reading_until, redir);
+! 			  push_heredoc ($$);
+  			}
+  	|	NUMBER LESS_LESS_MINUS WORD
+***************
+*** 522,526 ****
+  			  $$ = make_redirection
+  			    ($1, r_deblank_reading_until, redir);
+! 			  redir_stack[need_here_doc++] = $$;
+  			}
+  	|	GREATER_AND '-'
+--- 527,531 ----
+  			  $$ = make_redirection
+  			    ($1, r_deblank_reading_until, redir);
+! 			  push_heredoc ($$);
+  			}
+  	|	GREATER_AND '-'
+***************
+*** 2377,2380 ****
+--- 2382,2400 ----
+  static int esacs_needed_count;
+  
++ static void
++ push_heredoc (r)
++      REDIRECT *r;
++ {
++   if (need_here_doc >= HEREDOC_MAX)
++     {
++       last_command_exit_value = EX_BADUSAGE;
++       need_here_doc = 0;
++       report_syntax_error (_("maximum here-document count exceeded"));
++       reset_parser ();
++       exit_shell (last_command_exit_value);
++     }
++   redir_stack[need_here_doc++] = r;
++ }
++ 
+  void
+  gather_here_documents ()
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 41
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 42
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-043	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,59 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release:	4.0
+Patch-ID:	bash40-043
+
+Bug-Reported-by:	Michal Zalewski <[email protected]>
+Bug-Reference-ID:
+Bug-Reference-URL:
+
+Bug-Description:
+
+When bash is parsing a function definition that contains a here-document
+delimited by end-of-file (or end-of-string), it leaves the closing delimiter
+uninitialized.  This can result in an invalid memory access when the parsed
+function is later copied.
+
+Patch (apply with `patch -p0'):
+
+*** ../bash-4.0.42/make_cmd.c	2009-01-04 14:32:38.000000000 -0500
+--- make_cmd.c	2014-10-02 11:36:55.000000000 -0400
+***************
+*** 681,684 ****
+--- 681,685 ----
+    temp->redirector = source;
+    temp->redirectee = dest_and_filename;
++   temp->here_doc_eof = 0;
+    temp->instruction = instruction;
+    temp->flags = 0;
+*** ../bash-4.0.42/copy_cmd.c	2009-01-04 14:32:23.000000000 -0500
+--- copy_cmd.c	2014-10-02 11:36:55.000000000 -0400
+***************
+*** 119,123 ****
+      case r_reading_until:
+      case r_deblank_reading_until:
+!       new_redirect->here_doc_eof = savestring (redirect->here_doc_eof);
+        /*FALLTHROUGH*/
+      case r_reading_string:
+--- 119,123 ----
+      case r_reading_until:
+      case r_deblank_reading_until:
+!       new_redirect->here_doc_eof = redirect->here_doc_eof ? savestring (redirect->here_doc_eof) : 0;
+        /*FALLTHROUGH*/
+      case r_reading_string:
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 42
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 43
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/bash40-044	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,140 @@
+			     BASH PATCH REPORT
+			     =================
+
+Bash-Release: 4.0
+Patch-ID: bash40-044
+
+Bug-Reported-by:	Michal Zalewski <[email protected]>
+Bug-Reference-ID:
+Bug-Reference-URL:
+
+Bug-Description:
+
+A combination of nested command substitutions and function importing from
+the environment can cause bash to execute code appearing in the environment
+variable value following the function definition.
+
+Patch:
+
+*** ../bash-4.0.43/builtins/evalstring.c	2014-09-16 19:20:48.000000000 -0400
+--- builtins/evalstring.c	2014-10-04 15:33:32.000000000 -0400
+***************
+*** 44,47 ****
+--- 44,48 ----
+  #include "../redir.h"
+  #include "../trap.h"
++ #include "../bashintl.h"
+  
+  #include <y.tab.h>
+***************
+*** 259,268 ****
+  	      struct fd_bitmap *bitmap;
+  
+! 	      if ((flags & SEVAL_FUNCDEF) && command->type != cm_function_def)
+  		{
+! 		  internal_warning ("%s: ignoring function definition attempt", from_file);
+! 		  should_jump_to_top_level = 0;
+! 		  last_result = last_command_exit_value = EX_BADUSAGE;
+! 		  break;
+  		}
+  
+--- 260,282 ----
+  	      struct fd_bitmap *bitmap;
+  
+! 	      if (flags & SEVAL_FUNCDEF)
+  		{
+! 		  char *x;
+! 
+! 		  /* If the command parses to something other than a straight
+! 		     function definition, or if we have not consumed the entire
+! 		     string, or if the parser has transformed the function
+! 		     name (as parsing will if it begins or ends with shell
+! 		     whitespace, for example), reject the attempt */
+! 		  if (command->type != cm_function_def ||
+! 		      ((x = parser_remaining_input ()) && *x) ||
+! 		      (STREQ (from_file, command->value.Function_def->name->word) == 0))
+! 		    {
+! 		      internal_warning (_("%s: ignoring function definition attempt"), from_file);
+! 		      should_jump_to_top_level = 0;
+! 		      last_result = last_command_exit_value = EX_BADUSAGE;
+! 		      reset_parser ();
+! 		      break;
+! 		    }
+  		}
+  
+***************
+*** 329,333 ****
+  
+  	      if (flags & SEVAL_ONECMD)
+! 		break;
+  	    }
+  	}
+--- 343,350 ----
+  
+  	      if (flags & SEVAL_ONECMD)
+! 		{
+! 		  reset_parser ();
+! 		  break;
+! 		}
+  	    }
+  	}
+*** ../bash-4.0.43/parse.y	2014-09-30 19:41:09.000000000 -0400
+--- parse.y	2014-10-04 15:27:12.000000000 -0400
+***************
+*** 2279,2282 ****
+--- 2279,2292 ----
+  }
+  
++ char *
++ parser_remaining_input ()
++ {
++   if (shell_input_line == 0)
++     return 0;
++   if (shell_input_line_index < 0 || shell_input_line_index >= shell_input_line_len)
++     return '\0';	/* XXX */
++   return (shell_input_line + shell_input_line_index);
++ }
++ 
+  #ifdef INCLUDE_UNUSED
+  /* Back the input pointer up by one, effectively `ungetting' a character. */
+***************
+*** 3628,3633 ****
+    restore_parser_state (&ps);
+    reset_parser ();
+!   if (interactive)
+!     token_to_read = 0;
+  
+    /* Need to find how many characters parse_and_execute consumed, update
+--- 3638,3643 ----
+    restore_parser_state (&ps);
+    reset_parser ();
+! 
+!   token_to_read = 0;
+  
+    /* Need to find how many characters parse_and_execute consumed, update
+*** ../bash-4.0.43/shell.h	2009-01-04 14:32:41.000000000 -0500
+--- shell.h	2014-10-04 15:27:12.000000000 -0400
+***************
+*** 161,164 ****
+--- 161,166 ----
+  
+  /* Let's try declaring these here. */
++ extern char *parser_remaining_input __P((void));
++ 
+  extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *));
+  extern void restore_parser_state __P((sh_parser_state_t *));
+*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
+--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
+***************
+*** 26,30 ****
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 43
+  
+  #endif /* _PATCHLEVEL_H_ */
+--- 26,30 ----
+     looks for to find the patch level (for the sccs version string). */
+  
+! #define PATCHLEVEL 44
+  
+  #endif /* _PATCHLEVEL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/bash/Patches-4.0/disable-function-imports	Mon May 04 14:04:39 2015 +0100
@@ -0,0 +1,38 @@
+--- shell.c.orig	2009-01-04 19:32:41.000000000 +0000
++++ shell.c	2014-10-07 21:32:58.976889335 +0100
+@@ -225,7 +225,7 @@
+ #else
+ int posixly_correct = 0;	/* Non-zero means posix.2 superset. */
+ #endif
+-
++int import_functions = 0;       /* Import functions from environment */
+ 
+ /* Some long-winded argument names.  These are obviously new. */
+ #define Int 1
+@@ -245,6 +245,7 @@
+   { "help", Int, &want_initial_help, (char **)0x0 },
+   { "init-file", Charp, (int *)0x0, &bashrc_file },
+   { "login", Int, &make_login_shell, (char **)0x0 },
++  { "import-functions", Int, &import_functions, (char **)0x0 },
+   { "noediting", Int, &no_line_editing, (char **)0x0 },
+   { "noprofile", Int, &no_profile, (char **)0x0 },
+   { "norc", Int, &no_rc, (char **)0x0 },
+--- variables.c.orig	2014-10-07 23:39:11.759973975 +0100
++++ variables.c	2014-10-08 12:29:14.858891509 +0100
+@@ -102,6 +102,7 @@
+ extern time_t shell_start_time;
+ extern int assigning_in_environment;
+ extern int executing_builtin;
++extern int import_functions;
+ 
+ #if defined (READLINE)
+ extern int no_line_editing;
+@@ -339,7 +340,7 @@
+ 
+       /* If exported function, define it now.  Don't import functions from
+ 	 the environment in privileged mode. */
+-      if (privmode == 0 && read_but_dont_execute == 0 &&
++      if (import_functions && privmode == 0 && read_but_dont_execute == 0 &&
+ 	  STREQN (BASHFUNC_PREFIX, name, BASHFUNC_PREFLEN) &&
+ 	  STREQ (BASHFUNC_SUFFIX, name + char_index - BASHFUNC_SUFFLEN) &&
+ 	  STREQN ("() {", string, 4))
--- a/usr/src/cmd/bash/Solaris/apply_patches.sh	Sat Jan 18 20:08:55 2014 +0000
+++ b/usr/src/cmd/bash/Solaris/apply_patches.sh	Mon May 04 14:04:39 2015 +0100
@@ -56,7 +56,24 @@
     bash40-025 \
     bash40-026 \
     bash40-027 \
-    bash40-028
+    bash40-028 \
+    bash40-029 \
+    bash40-030 \
+    bash40-031 \
+    bash40-032 \
+    bash40-033 \
+    bash40-034 \
+    bash40-035 \
+    bash40-036 \
+    bash40-037 \
+    bash40-038 \
+    bash40-039 \
+    bash40-040 \
+    bash40-041 \
+    bash40-042 \
+    bash40-043 \
+    bash40-044 \
+    disable-function-imports
 do
     if [ ! -f ${PATCHDB}/${file}.applied ] ; then
         echo "Applying upstream bash 4.0 patch ${file}."