07a490
			     BASH PATCH REPORT
07a490
			     =================
07a490
07a490
Bash-Release:	4.2
07a490
Patch-ID:	bash42-012
07a490
07a490
Bug-Reported-by:	Rui Santos <rsantos@grupopie.com>
07a490
Bug-Reference-ID:	<4E04C6D0.2020507@grupopie.com>
07a490
Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2011-06/msg00079.html
07a490
07a490
Bug-Description:
07a490
07a490
When calling the parser to recursively parse a command substitution within
07a490
an arithmetic expansion, the shell overwrote the saved shell input line and
07a490
associated state, resulting in a garbled command.
07a490
07a490
Patch (apply with `patch -p0'):
07a490
07a490
*** ../bash-4.2-patched/parse.y	2011-02-26 19:19:05.000000000 -0500
07a490
--- parse.y	2011-06-24 20:08:22.000000000 -0400
07a490
***************
07a490
*** 3843,3846 ****
07a490
--- 3849,3853 ----
07a490
  {
07a490
    sh_parser_state_t ps;
07a490
+   sh_input_line_state_t ls;
07a490
    int orig_ind, nc, sflags;
07a490
    char *ret, *s, *ep, *ostring;
07a490
***************
07a490
*** 3850,3857 ****
07a490
--- 3857,3866 ----
07a490
    ostring = string;
07a490
  
07a490
+ /*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/
07a490
    sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE;
07a490
    if (flags & SX_NOLONGJMP)
07a490
      sflags |= SEVAL_NOLONGJMP;
07a490
    save_parser_state (&ps);
07a490
+   save_input_line_state (&ls);
07a490
  
07a490
    /*(*/
07a490
***************
07a490
*** 3862,3865 ****
07a490
--- 3871,3876 ----
07a490
    restore_parser_state (&ps);
07a490
    reset_parser ();
07a490
+   /* reset_parser clears shell_input_line and associated variables */
07a490
+   restore_input_line_state (&ls);
07a490
    if (interactive)
07a490
      token_to_read = 0;
07a490
***************
07a490
*** 5909,5912 ****
07a490
--- 5920,5929 ----
07a490
    ps->echo_input_at_read = echo_input_at_read;
07a490
  
07a490
+   ps->token = token;
07a490
+   ps->token_buffer_size = token_buffer_size;
07a490
+   /* Force reallocation on next call to read_token_word */
07a490
+   token = 0;
07a490
+   token_buffer_size = 0;
07a490
+ 
07a490
    return (ps);
07a490
  }
07a490
***************
07a490
*** 5950,5953 ****
07a490
--- 5967,6006 ----
07a490
    expand_aliases = ps->expand_aliases;
07a490
    echo_input_at_read = ps->echo_input_at_read;
07a490
+ 
07a490
+   FREE (token);
07a490
+   token = ps->token;
07a490
+   token_buffer_size = ps->token_buffer_size;
07a490
+ }
07a490
+ 
07a490
+ sh_input_line_state_t *
07a490
+ save_input_line_state (ls)
07a490
+      sh_input_line_state_t *ls;
07a490
+ {
07a490
+   if (ls == 0)
07a490
+     ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t));
07a490
+   if (ls == 0)
07a490
+     return ((sh_input_line_state_t *)NULL);
07a490
+ 
07a490
+   ls->input_line = shell_input_line;
07a490
+   ls->input_line_size = shell_input_line_size;
07a490
+   ls->input_line_len = shell_input_line_len;
07a490
+   ls->input_line_index = shell_input_line_index;
07a490
+ 
07a490
+   /* force reallocation */
07a490
+   shell_input_line = 0;
07a490
+   shell_input_line_size = shell_input_line_len = shell_input_line_index = 0;
07a490
+ }
07a490
+ 
07a490
+ void
07a490
+ restore_input_line_state (ls)
07a490
+      sh_input_line_state_t *ls;
07a490
+ {
07a490
+   FREE (shell_input_line);
07a490
+   shell_input_line = ls->input_line;
07a490
+   shell_input_line_size = ls->input_line_size;
07a490
+   shell_input_line_len = ls->input_line_len;
07a490
+   shell_input_line_index = ls->input_line_index;
07a490
+ 
07a490
+   set_line_mbstate ();
07a490
  }
07a490
  
07a490
*** ../bash-4.2-patched/shell.h	2011-01-06 22:16:55.000000000 -0500
07a490
--- shell.h	2011-06-24 19:12:25.000000000 -0400
07a490
***************
07a490
*** 137,140 ****
07a490
--- 139,145 ----
07a490
    int *token_state;
07a490
  
07a490
+   char *token;
07a490
+   int token_buffer_size;
07a490
+ 
07a490
    /* input line state -- line number saved elsewhere */
07a490
    int input_line_terminator;
07a490
***************
07a490
*** 167,171 ****
07a490
--- 172,186 ----
07a490
  } sh_parser_state_t;
07a490
  
07a490
+ typedef struct _sh_input_line_state_t {
07a490
+   char *input_line;
07a490
+   int input_line_index;
07a490
+   int input_line_size;
07a490
+   int input_line_len;
07a490
+ } sh_input_line_state_t;
07a490
+ 
07a490
  /* Let's try declaring these here. */
07a490
  extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *));
07a490
  extern void restore_parser_state __P((sh_parser_state_t *));
07a490
+ 
07a490
+ extern sh_input_line_state_t *save_input_line_state __P((sh_input_line_state_t *));
07a490
+ extern void restore_input_line_state __P((sh_input_line_state_t *));
07a490
*** ../bash-4.2-patched/patchlevel.h	Sat Jun 12 20:14:48 2010
07a490
--- patchlevel.h	Thu Feb 24 21:41:34 2011
07a490
***************
07a490
*** 26,30 ****
07a490
     looks for to find the patch level (for the sccs version string). */
07a490
  
07a490
! #define PATCHLEVEL 11
07a490
  
07a490
  #endif /* _PATCHLEVEL_H_ */
07a490
--- 26,30 ----
07a490
     looks for to find the patch level (for the sccs version string). */
07a490
  
07a490
! #define PATCHLEVEL 12
07a490
  
07a490
  #endif /* _PATCHLEVEL_H_ */