~ubuntu-branches/ubuntu/lucid/bash/lucid

« back to all changes in this revision

Viewing changes to debian/patches/bash40-007.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-08-24 12:06:59 UTC
  • mfrom: (1.3.2 upstream) (2.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090824120659-gmp1uuy2w9k2st53
Tags: 4.0-4ubuntu1
* Merge with Debian; remaining changes:
  - Build from the upstream sources, build the documentation in info format.
  - /etc/skel/.bashrc: eval lesspipe.
* Changes to the skeleton .bashrc:
  - Source .bash_aliases after defining aliases. LP: #400686.
  - Enable color support for grep. LP: #386502.
* The bash docs now  describe uname -s not having any effect on many
  systems. LP: #378595.
* Don't ship an info dir file. LP: #358932.
* Fix some lintian warnings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh -e
 
2
 
 
3
if [ $# -eq 3 -a "$2" = '-d' ]; then
 
4
    pdir="-d $3"
 
5
elif [ $# -ne 1 ]; then
 
6
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
 
7
    exit 1
 
8
fi
 
9
case "$1" in
 
10
    -patch) patch $pdir -f --no-backup-if-mismatch -p0 < $0;;
 
11
    -unpatch) patch $pdir -f --no-backup-if-mismatch -R -p0 < $0;;
 
12
    *)
 
13
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
 
14
        exit 1
 
15
esac
 
16
exit 0
 
17
 
 
18
# DP: bash-4.0 upstream fix 007
 
19
 
 
20
                             BASH PATCH REPORT
 
21
                             =================
 
22
 
 
23
Bash-Release: 4.0
 
24
Patch-ID: bash40-007
 
25
 
 
26
Bug-Reported-by:        AnMaster <anmaster@tele2.se>
 
27
Bug-Reference-ID:       <49A41C18.80807@tele2.se>
 
28
Bug-Reference-URL:      http://lists.gnu.org/archive/html/bug-bash/2009-02/msg00188.html
 
29
 
 
30
Bug-Description:
 
31
 
 
32
Bash had a number of problems parsing associative array subscripts containing
 
33
special characters.  The subscripts are supposed to be read as if they are
 
34
enclosed between double quotes.
 
35
 
 
36
Patch:
 
37
 
 
38
*** ../bash-4.0/parse.y 2009-01-08 08:29:12.000000000 -0500
 
39
--- parse.y     2009-02-25 17:25:56.000000000 -0500
 
40
***************
 
41
*** 2919,2922 ****
 
42
--- 2919,2923 ----
 
43
  #define P_COMMAND     0x08    /* parsing a command, so look for comments */
 
44
  #define P_BACKQUOTE   0x10    /* parsing a backquoted command substitution */
 
45
+ #define P_ARRAYSUB    0x20    /* parsing a [...] array subscript for assignment */
 
46
  
 
47
  /* Lexical state while parsing a grouping construct or $(...). */
 
48
***************
 
49
*** 3134,3137 ****
 
50
--- 3134,3139 ----
 
51
              FREE (nestret);
 
52
            }
 
53
+         else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '['))      /* ) } ] */
 
54
+           goto parse_dollar_word;
 
55
        }
 
56
        /* Parse an old-style command substitution within double quotes as a
 
57
***************
 
58
*** 3150,3153 ****
 
59
--- 3150,3154 ----
 
60
        /* check for $(), $[], or ${} inside quoted string. */
 
61
        {
 
62
+ parse_dollar_word:
 
63
          if (open == ch)       /* undo previous increment */
 
64
            count--;
 
65
***************
 
66
*** 4277,4281 ****
 
67
                      (token_index == 0 && (parser_state&PST_COMPASSIGN))))
 
68
          {
 
69
!         ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
 
70
          if (ttok == &matched_pair_error)
 
71
            return -1;          /* Bail immediately. */
 
72
--- 4277,4281 ----
 
73
                      (token_index == 0 && (parser_state&PST_COMPASSIGN))))
 
74
          {
 
75
!         ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
 
76
          if (ttok == &matched_pair_error)
 
77
            return -1;          /* Bail immediately. */
 
78
*** ../bash-4.0/arrayfunc.c     2009-01-04 14:32:21.000000000 -0500
 
79
--- arrayfunc.c 2009-02-25 07:58:54.000000000 -0500
 
80
***************
 
81
*** 605,666 ****
 
82
  }
 
83
  
 
84
! /* This function assumes s[i] == '['; returns with s[ret] == ']' if
 
85
!    an array subscript is correctly parsed. */
 
86
! int
 
87
! skipsubscript (s, i)
 
88
!      const char *s;
 
89
!      int i;
 
90
! {
 
91
!   int count, c;
 
92
! #if defined (HANDLE_MULTIBYTE)
 
93
!   mbstate_t state, state_bak;
 
94
!   size_t slength, mblength;
 
95
! #endif
 
96
 
97
! #if defined (HANDLE_MULTIBYTE)
 
98
!   memset (&state, '\0', sizeof (mbstate_t));
 
99
!   slength = strlen (s + i);
 
100
! #endif
 
101
!   
 
102
!   count = 1;
 
103
!   while (count)
 
104
!     {
 
105
!       /* Advance one (possibly multibyte) character in S starting at I. */
 
106
! #if defined (HANDLE_MULTIBYTE)
 
107
!       if (MB_CUR_MAX > 1)
 
108
!       {
 
109
!         state_bak = state;
 
110
!         mblength = mbrlen (s + i, slength, &state);
 
111
 
112
!         if (MB_INVALIDCH (mblength))
 
113
!           {
 
114
!             state = state_bak;
 
115
!             i++;
 
116
!             slength--;
 
117
!           }
 
118
!         else if (MB_NULLWCH (mblength))
 
119
!           return i;
 
120
!         else
 
121
!           {
 
122
!             i += mblength;
 
123
!             slength -= mblength;
 
124
!           }
 
125
!       }
 
126
!       else
 
127
! #endif
 
128
!       ++i;
 
129
 
130
!       c = s[i];
 
131
 
132
!       if (c == 0)
 
133
!       break;
 
134
!       else if (c == '[')
 
135
!       count++;
 
136
!       else if (c == ']')
 
137
!       count--;
 
138
!     }
 
139
 
140
!   return i;
 
141
! }
 
142
  
 
143
  /* This function is called with SUB pointing to just after the beginning
 
144
--- 605,609 ----
 
145
  }
 
146
  
 
147
! /* skipsubscript moved to subst.c to use private functions. 2009/02/24. */
 
148
  
 
149
  /* This function is called with SUB pointing to just after the beginning
 
150
*** ../bash-4.0/subst.c 2009-01-28 14:34:12.000000000 -0500
 
151
--- subst.c     2009-02-25 09:18:33.000000000 -0500
 
152
***************
 
153
*** 223,226 ****
 
154
--- 223,227 ----
 
155
  static char *extract_delimited_string __P((char *, int *, char *, char *, char *, int));
 
156
  static char *extract_dollar_brace_string __P((char *, int *, int, int));
 
157
+ static int skip_matched_pair __P((const char *, int, int, int, int));
 
158
  
 
159
  static char *pos_params __P((char *, int, int, int));
 
160
***************
 
161
*** 1375,1378 ****
 
162
--- 1376,1480 ----
 
163
  #define CQ_RETURN(x) do { no_longjmp_on_fatal_error = 0; return (x); } while (0)
 
164
  
 
165
+ /* This function assumes s[i] == open; returns with s[ret] == close; used to
 
166
+    parse array subscripts.  FLAGS currently unused. */
 
167
+ static int
 
168
+ skip_matched_pair (string, start, open, close, flags)
 
169
+      const char *string;
 
170
+      int start, open, close, flags;
 
171
+ {
 
172
+   int i, pass_next, backq, si, c, count;
 
173
+   size_t slen;
 
174
+   char *temp, *ss;
 
175
+   DECLARE_MBSTATE;
 
176
 
177
+   slen = strlen (string + start) + start;
 
178
+   no_longjmp_on_fatal_error = 1;
 
179
 
180
+   i = start + 1;              /* skip over leading bracket */
 
181
+   count = 1;
 
182
+   pass_next = backq = 0;
 
183
+   ss = (char *)string;
 
184
+   while (c = string[i])
 
185
+     {
 
186
+       if (pass_next)
 
187
+       {
 
188
+         pass_next = 0;
 
189
+         if (c == 0)
 
190
+           CQ_RETURN(i);
 
191
+         ADVANCE_CHAR (string, slen, i);
 
192
+         continue;
 
193
+       }
 
194
+       else if (c == '\\')
 
195
+       {
 
196
+         pass_next = 1;
 
197
+         i++;
 
198
+         continue;
 
199
+       }
 
200
+       else if (backq)
 
201
+       {
 
202
+         if (c == '`')
 
203
+           backq = 0;
 
204
+         ADVANCE_CHAR (string, slen, i);
 
205
+         continue;
 
206
+       }
 
207
+       else if (c == '`')
 
208
+       {
 
209
+         backq = 1;
 
210
+         i++;
 
211
+         continue;
 
212
+       }
 
213
+       else if (c == open)
 
214
+       {
 
215
+         count++;
 
216
+         i++;
 
217
+         continue;
 
218
+       }
 
219
+       else if (c == close)
 
220
+       {
 
221
+         count--;
 
222
+         if (count == 0)
 
223
+           break;
 
224
+         i++;
 
225
+         continue;
 
226
+       }
 
227
+       else if (c == '\'' || c == '"')
 
228
+       {
 
229
+         i = (c == '\'') ? skip_single_quoted (ss, slen, ++i)
 
230
+                         : skip_double_quoted (ss, slen, ++i);
 
231
+         /* no increment, the skip functions increment past the closing quote. */
 
232
+       }
 
233
+       else if (c == '$' && (string[i+1] == LPAREN || string[i+1] == LBRACE))
 
234
+       {
 
235
+         si = i + 2;
 
236
+         if (string[si] == '\0')
 
237
+           CQ_RETURN(si);
 
238
 
239
+         if (string[i+1] == LPAREN)
 
240
+           temp = extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */
 
241
+         else
 
242
+           temp = extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC);
 
243
+         i = si;
 
244
+         if (string[i] == '\0')        /* don't increment i past EOS in loop */
 
245
+           break;
 
246
+         i++;
 
247
+         continue;
 
248
+       }
 
249
+       else
 
250
+       ADVANCE_CHAR (string, slen, i);
 
251
+     }
 
252
 
253
+   CQ_RETURN(i);
 
254
+ }
 
255
 
256
+ #if defined (ARRAY_VARS)
 
257
+ int
 
258
+ skipsubscript (string, start)
 
259
+      const char *string;
 
260
+      int start;
 
261
+ {
 
262
+   return (skip_matched_pair (string, start, '[', ']', 0));
 
263
+ }
 
264
+ #endif
 
265
 
266
  /* Skip characters in STRING until we find a character in DELIMS, and return
 
267
     the index of that character.  START is the index into string at which we
 
268
*** ../bash-4.0/patchlevel.h    2009-01-04 14:32:40.000000000 -0500
 
269
--- patchlevel.h        2009-02-22 16:11:31.000000000 -0500
 
270
***************
 
271
*** 26,30 ****
 
272
     looks for to find the patch level (for the sccs version string). */
 
273
  
 
274
! #define PATCHLEVEL 6
 
275
  
 
276
  #endif /* _PATCHLEVEL_H_ */
 
277
--- 26,30 ----
 
278
     looks for to find the patch level (for the sccs version string). */
 
279
  
 
280
! #define PATCHLEVEL 7
 
281
  
 
282
  #endif /* _PATCHLEVEL_H_ */