rcolebaugh / rpms / bash

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