Ondrej Oprala f96c39
			     BASH PATCH REPORT
Ondrej Oprala f96c39
			     =================
Ondrej Oprala f96c39
Ondrej Oprala f96c39
Bash-Release:	4.3
Ondrej Oprala f96c39
Patch-ID:	bash43-030
Ondrej Oprala f96c39
Ondrej Oprala f96c39
Bug-Reported-by:	Michal Zalewski <lcamtuf@coredump.cx>
Ondrej Oprala f96c39
Bug-Reference-ID:
Ondrej Oprala f96c39
Bug-Reference-URL:
Ondrej Oprala f96c39
Ondrej Oprala f96c39
Bug-Description:
Ondrej Oprala f96c39
Ondrej Oprala f96c39
A combination of nested command substitutions and function importing from
Ondrej Oprala f96c39
the environment can cause bash to execute code appearing in the environment
Ondrej Oprala f96c39
variable value following the function definition.
Ondrej Oprala f96c39
Ondrej Oprala f96c39
Patch (apply with `patch -p0'):
Ondrej Oprala f96c39
Ondrej Oprala f96c39
*** ../bash-4.3.29/builtins/evalstring.c	2014-10-01 12:57:47.000000000 -0400
Ondrej Oprala f96c39
--- builtins/evalstring.c	2014-10-03 11:57:04.000000000 -0400
Ondrej Oprala f96c39
***************
Ondrej Oprala f96c39
*** 309,318 ****
Ondrej Oprala f96c39
  	      struct fd_bitmap *bitmap;
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
! 	      if ((flags & SEVAL_FUNCDEF) && command->type != cm_function_def)
Ondrej Oprala f96c39
  		{
Ondrej Oprala f96c39
! 		  internal_warning ("%s: ignoring function definition attempt", from_file);
Ondrej Oprala f96c39
! 		  should_jump_to_top_level = 0;
Ondrej Oprala f96c39
! 		  last_result = last_command_exit_value = EX_BADUSAGE;
Ondrej Oprala f96c39
! 		  break;
Ondrej Oprala f96c39
  		}
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
--- 313,335 ----
Ondrej Oprala f96c39
  	      struct fd_bitmap *bitmap;
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
! 	      if (flags & SEVAL_FUNCDEF)
Ondrej Oprala f96c39
  		{
Ondrej Oprala f96c39
! 		  char *x;
Ondrej Oprala f96c39
! 
Ondrej Oprala f96c39
! 		  /* If the command parses to something other than a straight
Ondrej Oprala f96c39
! 		     function definition, or if we have not consumed the entire
Ondrej Oprala f96c39
! 		     string, or if the parser has transformed the function
Ondrej Oprala f96c39
! 		     name (as parsing will if it begins or ends with shell
Ondrej Oprala f96c39
! 		     whitespace, for example), reject the attempt */
Ondrej Oprala f96c39
! 		  if (command->type != cm_function_def ||
Ondrej Oprala f96c39
! 		      ((x = parser_remaining_input ()) && *x) ||
Ondrej Oprala f96c39
! 		      (STREQ (from_file, command->value.Function_def->name->word) == 0))
Ondrej Oprala f96c39
! 		    {
Ondrej Oprala f96c39
! 		      internal_warning (_("%s: ignoring function definition attempt"), from_file);
Ondrej Oprala f96c39
! 		      should_jump_to_top_level = 0;
Ondrej Oprala f96c39
! 		      last_result = last_command_exit_value = EX_BADUSAGE;
Ondrej Oprala f96c39
! 		      reset_parser ();
Ondrej Oprala f96c39
! 		      break;
Ondrej Oprala f96c39
! 		    }
Ondrej Oprala f96c39
  		}
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
***************
Ondrej Oprala f96c39
*** 379,383 ****
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
  	      if (flags & SEVAL_ONECMD)
Ondrej Oprala f96c39
! 		break;
Ondrej Oprala f96c39
  	    }
Ondrej Oprala f96c39
  	}
Ondrej Oprala f96c39
--- 396,403 ----
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
  	      if (flags & SEVAL_ONECMD)
Ondrej Oprala f96c39
! 		{
Ondrej Oprala f96c39
! 		  reset_parser ();
Ondrej Oprala f96c39
! 		  break;
Ondrej Oprala f96c39
! 		}
Ondrej Oprala f96c39
  	    }
Ondrej Oprala f96c39
  	}
Ondrej Oprala f96c39
*** ../bash-4.3.29/parse.y	2014-10-01 12:58:43.000000000 -0400
Ondrej Oprala f96c39
--- parse.y	2014-10-03 14:48:59.000000000 -0400
Ondrej Oprala f96c39
***************
Ondrej Oprala f96c39
*** 2539,2542 ****
Ondrej Oprala f96c39
--- 2539,2552 ----
Ondrej Oprala f96c39
  }
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
+ char *
Ondrej Oprala f96c39
+ parser_remaining_input ()
Ondrej Oprala f96c39
+ {
Ondrej Oprala f96c39
+   if (shell_input_line == 0)
Ondrej Oprala f96c39
+     return 0;
Ondrej Oprala f96c39
+   if (shell_input_line_index < 0 || shell_input_line_index >= shell_input_line_len)
Ondrej Oprala f96c39
+     return '\0';	/* XXX */
Ondrej Oprala f96c39
+   return (shell_input_line + shell_input_line_index);
Ondrej Oprala f96c39
+ }
Ondrej Oprala f96c39
+ 
Ondrej Oprala f96c39
  #ifdef INCLUDE_UNUSED
Ondrej Oprala f96c39
  /* Back the input pointer up by one, effectively `ungetting' a character. */
Ondrej Oprala f96c39
***************
Ondrej Oprala f96c39
*** 4028,4033 ****
Ondrej Oprala f96c39
    /* reset_parser clears shell_input_line and associated variables */
Ondrej Oprala f96c39
    restore_input_line_state (&ls);
Ondrej Oprala f96c39
!   if (interactive)
Ondrej Oprala f96c39
!     token_to_read = 0;
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
    /* Need to find how many characters parse_and_execute consumed, update
Ondrej Oprala f96c39
--- 4053,4058 ----
Ondrej Oprala f96c39
    /* reset_parser clears shell_input_line and associated variables */
Ondrej Oprala f96c39
    restore_input_line_state (&ls);
Ondrej Oprala f96c39
! 
Ondrej Oprala f96c39
!   token_to_read = 0;
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
    /* Need to find how many characters parse_and_execute consumed, update
Ondrej Oprala f96c39
*** ../bash-4.3.29/shell.h	2014-10-01 12:57:39.000000000 -0400
Ondrej Oprala f96c39
--- shell.h	2014-10-03 14:49:12.000000000 -0400
Ondrej Oprala f96c39
***************
Ondrej Oprala f96c39
*** 181,184 ****
Ondrej Oprala f96c39
--- 181,186 ----
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
  /* Let's try declaring these here. */
Ondrej Oprala f96c39
+ extern char *parser_remaining_input __P((void));
Ondrej Oprala f96c39
+ 
Ondrej Oprala f96c39
  extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *));
Ondrej Oprala f96c39
  extern void restore_parser_state __P((sh_parser_state_t *));
Ondrej Oprala f96c39
*** ../bash-4.3/patchlevel.h	2012-12-29 10:47:57.000000000 -0500
Ondrej Oprala f96c39
--- patchlevel.h	2014-03-20 20:01:28.000000000 -0400
Ondrej Oprala f96c39
***************
Ondrej Oprala f96c39
*** 26,30 ****
Ondrej Oprala f96c39
     looks for to find the patch level (for the sccs version string). */
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
! #define PATCHLEVEL 29
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
  #endif /* _PATCHLEVEL_H_ */
Ondrej Oprala f96c39
--- 26,30 ----
Ondrej Oprala f96c39
     looks for to find the patch level (for the sccs version string). */
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
! #define PATCHLEVEL 30
Ondrej Oprala f96c39
  
Ondrej Oprala f96c39
  #endif /* _PATCHLEVEL_H_ */