Branch oldpackages for 14.07
[14.07/packages.git] / utils / bash / patches / 112-upstream-bash42-012.patch
1                              BASH PATCH REPORT
2                              =================
3
4 Bash-Release:   4.2
5 Patch-ID:       bash42-012
6
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
10
11 Bug-Description:
12
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.
16
17 Patch (apply with `patch -p0'):
18
19 --- a/parse.y
20 +++ b/parse.y
21 @@ -3842,6 +3842,7 @@ xparse_dolparen (base, string, indp, fla
22       int flags;
23  {
24    sh_parser_state_t ps;
25 +  sh_input_line_state_t ls;
26    int orig_ind, nc, sflags;
27    char *ret, *s, *ep, *ostring;
28  
29 @@ -3849,10 +3850,12 @@ xparse_dolparen (base, string, indp, fla
30    orig_ind = *indp;
31    ostring = string;
32  
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);
39  
40    /*(*/
41    parser_state |= PST_CMDSUBST|PST_EOFTOKEN;   /* allow instant ')' */ /*(*/
42 @@ -3861,6 +3864,8 @@ xparse_dolparen (base, string, indp, fla
43  
44    restore_parser_state (&ps);
45    reset_parser ();
46 +  /* reset_parser clears shell_input_line and associated variables */
47 +  restore_input_line_state (&ls);
48    if (interactive)
49      token_to_read = 0;
50  
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;
54  
55 +  ps->token = token;
56 +  ps->token_buffer_size = token_buffer_size;
57 +  /* Force reallocation on next call to read_token_word */
58 +  token = 0;
59 +  token_buffer_size = 0;
60 +
61    return (ps);
62  }
63  
64 @@ -5949,6 +5960,42 @@ restore_parser_state (ps)
65  
66    expand_aliases = ps->expand_aliases;
67    echo_input_at_read = ps->echo_input_at_read;
68 +
69 +  FREE (token);
70 +  token = ps->token;
71 +  token_buffer_size = ps->token_buffer_size;
72 +}
73 +
74 +sh_input_line_state_t *
75 +save_input_line_state (ls)
76 +     sh_input_line_state_t *ls;
77 +{
78 +  if (ls == 0)
79 +    ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t));
80 +  if (ls == 0)
81 +    return ((sh_input_line_state_t *)NULL);
82 +
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;
87 +
88 +  /* force reallocation */
89 +  shell_input_line = 0;
90 +  shell_input_line_size = shell_input_line_len = shell_input_line_index = 0;
91 +}
92 +
93 +void
94 +restore_input_line_state (ls)
95 +     sh_input_line_state_t *ls;
96 +{
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;
102 +
103 +  set_line_mbstate ();
104  }
105  
106  /************************************************
107 --- a/shell.h
108 +++ b/shell.h
109 @@ -136,6 +136,9 @@ typedef struct _sh_parser_state_t {
110    int parser_state;
111    int *token_state;
112  
113 +  char *token;
114 +  int token_buffer_size;
115 +
116    /* input line state -- line number saved elsewhere */
117    int input_line_terminator;
118    int eof_encountered;
119 @@ -166,6 +169,16 @@ typedef struct _sh_parser_state_t {
120    
121  } sh_parser_state_t;
122  
123 +typedef struct _sh_input_line_state_t {
124 +  char *input_line;
125 +  int input_line_index;
126 +  int input_line_size;
127 +  int input_line_len;
128 +} sh_input_line_state_t;
129 +
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 *));
133 +
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 *));
136 --- a/patchlevel.h
137 +++ b/patchlevel.h
138 @@ -25,6 +25,6 @@
139     regexp `^#define[   ]*PATCHLEVEL', since that's what support/mkversion.sh
140     looks for to find the patch level (for the sccs version string). */
141  
142 -#define PATCHLEVEL 11
143 +#define PATCHLEVEL 12
144  
145  #endif /* _PATCHLEVEL_H_ */