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'):
25 + sh_input_line_state_t ls;
26 int orig_ind, nc, sflags;
27 char *ret, *s, *ep, *ostring;
29 @@ -3849,10 +3850,12 @@
33 +/*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/
34 sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE;
35 if (flags & SX_NOLONGJMP)
36 sflags |= SEVAL_NOLONGJMP;
37 save_parser_state (&ps);
38 + save_input_line_state (&ls);
41 parser_state |= PST_CMDSUBST|PST_EOFTOKEN; /* allow instant ')' */ /*(*/
44 restore_parser_state (&ps);
46 + /* reset_parser clears shell_input_line and associated variables */
47 + restore_input_line_state (&ls);
51 @@ -5908,6 +5913,12 @@
52 ps->expand_aliases = expand_aliases;
53 ps->echo_input_at_read = echo_input_at_read;
56 + ps->token_buffer_size = token_buffer_size;
57 + /* Force reallocation on next call to read_token_word */
59 + token_buffer_size = 0;
64 @@ -5949,6 +5960,42 @@
66 expand_aliases = ps->expand_aliases;
67 echo_input_at_read = ps->echo_input_at_read;
71 + token_buffer_size = ps->token_buffer_size;
74 +sh_input_line_state_t *
75 +save_input_line_state (ls)
76 + sh_input_line_state_t *ls;
79 + ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t));
81 + return ((sh_input_line_state_t *)NULL);
83 + ls->input_line = shell_input_line;
84 + ls->input_line_size = shell_input_line_size;
85 + ls->input_line_len = shell_input_line_len;
86 + ls->input_line_index = shell_input_line_index;
88 + /* force reallocation */
89 + shell_input_line = 0;
90 + shell_input_line_size = shell_input_line_len = shell_input_line_index = 0;
94 +restore_input_line_state (ls)
95 + sh_input_line_state_t *ls;
97 + FREE (shell_input_line);
98 + shell_input_line = ls->input_line;
99 + shell_input_line_size = ls->input_line_size;
100 + shell_input_line_len = ls->input_line_len;
101 + shell_input_line_index = ls->input_line_index;
103 + set_line_mbstate ();
106 /************************************************
107 --- a/bash/patchlevel.h
108 +++ b/bash/patchlevel.h
110 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
111 looks for to find the patch level (for the sccs version string). */
113 -#define PATCHLEVEL 11
114 +#define PATCHLEVEL 12
116 #endif /* _PATCHLEVEL_H_ */
124 + int token_buffer_size;
126 /* input line state -- line number saved elsewhere */
127 int input_line_terminator;
133 +typedef struct _sh_input_line_state_t {
135 + int input_line_index;
136 + int input_line_size;
137 + int input_line_len;
138 +} sh_input_line_state_t;
140 /* Let's try declaring these here. */
141 extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *));
142 extern void restore_parser_state __P((sh_parser_state_t *));
144 +extern sh_input_line_state_t *save_input_line_state __P((sh_input_line_state_t *));
145 +extern void restore_input_line_state __P((sh_input_line_state_t *));