7 Bug-Reported-by: Rui Santos <rsantos@grupopie.com>
8 Bug-Reference-ID: <4E04C6D0.2020507@grupopie.com>
9 Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2011-06/msg00079.html
13 When calling the parser to recursively parse a command substitution within
14 an arithmetic expansion, the shell overwrote the saved shell input line and
15 associated state, resulting in a garbled command.
17 Patch (apply with `patch -p0'):
19 *** ../bash-4.2-patched/parse.y 2011-02-26 19:19:05.000000000 -0500
20 --- parse.y 2011-06-24 20:08:22.000000000 -0400
26 + sh_input_line_state_t ls;
27 int orig_ind, nc, sflags;
28 char *ret, *s, *ep, *ostring;
34 + /*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/
35 sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE;
36 if (flags & SX_NOLONGJMP)
37 sflags |= SEVAL_NOLONGJMP;
38 save_parser_state (&ps);
39 + save_input_line_state (&ls);
45 restore_parser_state (&ps);
47 + /* reset_parser clears shell_input_line and associated variables */
48 + restore_input_line_state (&ls);
54 ps->echo_input_at_read = echo_input_at_read;
57 + ps->token_buffer_size = token_buffer_size;
58 + /* Force reallocation on next call to read_token_word */
60 + token_buffer_size = 0;
67 expand_aliases = ps->expand_aliases;
68 echo_input_at_read = ps->echo_input_at_read;
72 + token_buffer_size = ps->token_buffer_size;
75 + sh_input_line_state_t *
76 + save_input_line_state (ls)
77 + sh_input_line_state_t *ls;
80 + ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t));
82 + return ((sh_input_line_state_t *)NULL);
84 + ls->input_line = shell_input_line;
85 + ls->input_line_size = shell_input_line_size;
86 + ls->input_line_len = shell_input_line_len;
87 + ls->input_line_index = shell_input_line_index;
89 + /* force reallocation */
90 + shell_input_line = 0;
91 + shell_input_line_size = shell_input_line_len = shell_input_line_index = 0;
95 + restore_input_line_state (ls)
96 + sh_input_line_state_t *ls;
98 + FREE (shell_input_line);
99 + shell_input_line = ls->input_line;
100 + shell_input_line_size = ls->input_line_size;
101 + shell_input_line_len = ls->input_line_len;
102 + shell_input_line_index = ls->input_line_index;
104 + set_line_mbstate ();
107 *** ../bash-4.2-patched/shell.h 2011-01-06 22:16:55.000000000 -0500
108 --- shell.h 2011-06-24 19:12:25.000000000 -0400
115 + int token_buffer_size;
117 /* input line state -- line number saved elsewhere */
118 int input_line_terminator;
124 + typedef struct _sh_input_line_state_t {
126 + int input_line_index;
127 + int input_line_size;
128 + int input_line_len;
129 + } sh_input_line_state_t;
131 /* Let's try declaring these here. */
132 extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *));
133 extern void restore_parser_state __P((sh_parser_state_t *));
135 + extern sh_input_line_state_t *save_input_line_state __P((sh_input_line_state_t *));
136 + extern void restore_input_line_state __P((sh_input_line_state_t *));
137 *** ../bash-4.2-patched/patchlevel.h Sat Jun 12 20:14:48 2010
138 --- patchlevel.h Thu Feb 24 21:41:34 2011
141 looks for to find the patch level (for the sccs version string). */
143 ! #define PATCHLEVEL 11
145 #endif /* _PATCHLEVEL_H_ */
147 looks for to find the patch level (for the sccs version string). */
149 ! #define PATCHLEVEL 12
151 #endif /* _PATCHLEVEL_H_ */