svashisht / rpms / bash

Forked from rpms/bash 4 years ago
Clone

Blame SOURCES/bash42-012

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