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'):
21 @@ -3842,6 +3842,7 @@ xparse_dolparen (base, string, indp, fla
25 + sh_input_line_state_t ls;
26 int orig_ind, nc, sflags;
27 char *ret, *s, *ep, *ostring;
29 @@ -3849,10 +3850,12 @@ xparse_dolparen (base, string, indp, fla
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 ')' */ /*(*/
42 @@ -3861,6 +3864,8 @@ xparse_dolparen (base, string, indp, fla
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 @@ save_parser_state (ps)
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 @@ restore_parser_state (ps)
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 /************************************************
109 @@ -136,6 +136,9 @@ typedef struct _sh_parser_state_t {
114 + int token_buffer_size;
116 /* input line state -- line number saved elsewhere */
117 int input_line_terminator;
119 @@ -166,6 +169,16 @@ typedef struct _sh_parser_state_t {
123 +typedef struct _sh_input_line_state_t {
125 + int input_line_index;
126 + int input_line_size;
127 + int input_line_len;
128 +} sh_input_line_state_t;
130 /* Let's try declaring these here. */
131 extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *));
132 extern void restore_parser_state __P((sh_parser_state_t *));
134 +extern sh_input_line_state_t *save_input_line_state __P((sh_input_line_state_t *));
135 +extern void restore_input_line_state __P((sh_input_line_state_t *));
139 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
140 looks for to find the patch level (for the sccs version string). */
142 -#define PATCHLEVEL 11
143 +#define PATCHLEVEL 12
145 #endif /* _PATCHLEVEL_H_ */