[c822ddc] | 1 | Submitted By: Jim Gifford (jim at cross-lfs dot org)
|
---|
[7a39f29] | 2 | Date: 03-02-2009
|
---|
[c822ddc] | 3 | Initial Package Version: 4.0
|
---|
| 4 | Origin: Upstream
|
---|
| 5 | Upstream Status: Applied
|
---|
| 6 | Description: Fixes from the Mailing List - Bash Bug
|
---|
| 7 | http://lists.gnu.org/archive/html/bug-bash/2009-02/index.html
|
---|
| 8 |
|
---|
| 9 | diff -Naur bash-4.0.orig/arrayfunc.c bash-4.0/arrayfunc.c
|
---|
| 10 | --- bash-4.0.orig/arrayfunc.c 2009-01-04 11:32:21.000000000 -0800
|
---|
[7a39f29] | 11 | +++ bash-4.0/arrayfunc.c 2009-03-02 12:37:07.363274758 -0800
|
---|
[c822ddc] | 12 | @@ -604,64 +604,7 @@
|
---|
| 13 | }
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | -/* This function assumes s[i] == '['; returns with s[ret] == ']' if
|
---|
| 17 | - an array subscript is correctly parsed. */
|
---|
| 18 | -int
|
---|
| 19 | -skipsubscript (s, i)
|
---|
| 20 | - const char *s;
|
---|
| 21 | - int i;
|
---|
| 22 | -{
|
---|
| 23 | - int count, c;
|
---|
| 24 | -#if defined (HANDLE_MULTIBYTE)
|
---|
| 25 | - mbstate_t state, state_bak;
|
---|
| 26 | - size_t slength, mblength;
|
---|
| 27 | -#endif
|
---|
| 28 | -
|
---|
| 29 | -#if defined (HANDLE_MULTIBYTE)
|
---|
| 30 | - memset (&state, '\0', sizeof (mbstate_t));
|
---|
| 31 | - slength = strlen (s + i);
|
---|
| 32 | -#endif
|
---|
| 33 | -
|
---|
| 34 | - count = 1;
|
---|
| 35 | - while (count)
|
---|
| 36 | - {
|
---|
| 37 | - /* Advance one (possibly multibyte) character in S starting at I. */
|
---|
| 38 | -#if defined (HANDLE_MULTIBYTE)
|
---|
| 39 | - if (MB_CUR_MAX > 1)
|
---|
| 40 | - {
|
---|
| 41 | - state_bak = state;
|
---|
| 42 | - mblength = mbrlen (s + i, slength, &state);
|
---|
| 43 | -
|
---|
| 44 | - if (MB_INVALIDCH (mblength))
|
---|
| 45 | - {
|
---|
| 46 | - state = state_bak;
|
---|
| 47 | - i++;
|
---|
| 48 | - slength--;
|
---|
| 49 | - }
|
---|
| 50 | - else if (MB_NULLWCH (mblength))
|
---|
| 51 | - return i;
|
---|
| 52 | - else
|
---|
| 53 | - {
|
---|
| 54 | - i += mblength;
|
---|
| 55 | - slength -= mblength;
|
---|
| 56 | - }
|
---|
| 57 | - }
|
---|
| 58 | - else
|
---|
| 59 | -#endif
|
---|
| 60 | - ++i;
|
---|
| 61 | -
|
---|
| 62 | - c = s[i];
|
---|
| 63 | -
|
---|
| 64 | - if (c == 0)
|
---|
| 65 | - break;
|
---|
| 66 | - else if (c == '[')
|
---|
| 67 | - count++;
|
---|
| 68 | - else if (c == ']')
|
---|
| 69 | - count--;
|
---|
| 70 | - }
|
---|
| 71 | -
|
---|
| 72 | - return i;
|
---|
| 73 | -}
|
---|
| 74 | +/* skipsubscript moved to subst.c to use private functions. 2009/02/24. */
|
---|
| 75 |
|
---|
| 76 | /* This function is called with SUB pointing to just after the beginning
|
---|
| 77 | `[' of an array subscript and removes the array element to which SUB
|
---|
| 78 | diff -Naur bash-4.0.orig/builtins/declare.def bash-4.0/builtins/declare.def
|
---|
| 79 | --- bash-4.0.orig/builtins/declare.def 2009-01-04 11:32:22.000000000 -0800
|
---|
[7a39f29] | 80 | +++ bash-4.0/builtins/declare.def 2009-03-02 12:37:07.363274758 -0800
|
---|
[c822ddc] | 81 | @@ -287,6 +287,12 @@
|
---|
| 82 | name[offset - 1] = '\0';
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | + else if (legal_identifier (name) == 0)
|
---|
| 86 | + {
|
---|
| 87 | + sh_invalidid (name);
|
---|
| 88 | + assign_error++;
|
---|
| 89 | + NEXT_VARIABLE ();
|
---|
| 90 | + }
|
---|
| 91 | else
|
---|
| 92 | value = "";
|
---|
| 93 |
|
---|
| 94 | @@ -295,6 +301,13 @@
|
---|
| 95 | subscript_start = (char *)NULL;
|
---|
| 96 | if (t = strchr (name, '[')) /* ] */
|
---|
| 97 | {
|
---|
| 98 | + /* If offset != 0 we have already validated any array reference */
|
---|
| 99 | + if (offset == 0 && valid_array_reference (name) == 0)
|
---|
| 100 | + {
|
---|
| 101 | + sh_invalidid (name);
|
---|
| 102 | + assign_error++;
|
---|
| 103 | + NEXT_VARIABLE ();
|
---|
| 104 | + }
|
---|
| 105 | subscript_start = t;
|
---|
| 106 | *t = '\0';
|
---|
| 107 | making_array_special = 1;
|
---|
| 108 | @@ -484,7 +497,7 @@
|
---|
| 109 | }
|
---|
| 110 | /* declare -a name[[n]] or declare name[n] makes name an indexed
|
---|
| 111 | array variable. */
|
---|
| 112 | - else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0)
|
---|
| 113 | + else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0 && assoc_p (var) == 0)
|
---|
| 114 | var = convert_var_to_array (var);
|
---|
| 115 | #endif /* ARRAY_VARS */
|
---|
| 116 |
|
---|
| 117 | diff -Naur bash-4.0.orig/builtins/exit.def bash-4.0/builtins/exit.def
|
---|
| 118 | --- bash-4.0.orig/builtins/exit.def 2009-01-04 11:32:22.000000000 -0800
|
---|
[7a39f29] | 119 | +++ bash-4.0/builtins/exit.def 2009-03-02 12:37:07.367275038 -0800
|
---|
[c822ddc] | 120 | @@ -113,7 +113,7 @@
|
---|
| 121 | for (i = stopmsg = 0; i < js.j_jobslots; i++)
|
---|
| 122 | if (jobs[i] && STOPPED (i))
|
---|
| 123 | stopmsg = JSTOPPED;
|
---|
| 124 | - else if (check_jobs_at_exit && stopmsg == 0 && RUNNING (i))
|
---|
| 125 | + else if (check_jobs_at_exit && stopmsg == 0 && jobs[i] && RUNNING (i))
|
---|
| 126 | stopmsg = JRUNNING;
|
---|
| 127 |
|
---|
| 128 | if (stopmsg == JSTOPPED)
|
---|
[7a39f29] | 129 | diff -Naur bash-4.0.orig/builtins/read.def bash-4.0/builtins/read.def
|
---|
| 130 | --- bash-4.0.orig/builtins/read.def 2009-01-15 20:11:21.000000000 -0800
|
---|
| 131 | +++ bash-4.0/builtins/read.def 2009-03-02 13:01:12.743891046 -0800
|
---|
| 132 | @@ -369,14 +369,14 @@
|
---|
| 133 | code = setjmp (alrmbuf);
|
---|
| 134 | if (code)
|
---|
| 135 | {
|
---|
| 136 | -#if 0
|
---|
| 137 | + /* Tricky. The top of the unwind-protect stack is the free of
|
---|
| 138 | + input_string. We want to run all the rest and use input_string,
|
---|
| 139 | + so we have to remove it from the stack. */
|
---|
| 140 | + remove_unwind_protect ();
|
---|
| 141 | run_unwind_frame ("read_builtin");
|
---|
| 142 | - return (EXECUTION_FAILURE);
|
---|
| 143 | -#else
|
---|
| 144 | input_string[i] = '\0'; /* make sure it's terminated */
|
---|
| 145 | - retval = 128+SIGALRM;;
|
---|
| 146 | + retval = 128+SIGALRM;
|
---|
| 147 | goto assign_vars;
|
---|
| 148 | -#endif
|
---|
| 149 | }
|
---|
| 150 | old_alrm = set_signal_handler (SIGALRM, sigalrm);
|
---|
| 151 | add_unwind_protect (reset_alarm, (char *)NULL);
|
---|
[c822ddc] | 152 | diff -Naur bash-4.0.orig/parse.y bash-4.0/parse.y
|
---|
| 153 | --- bash-4.0.orig/parse.y 2009-01-08 05:29:12.000000000 -0800
|
---|
[7a39f29] | 154 | +++ bash-4.0/parse.y 2009-03-02 12:37:07.367275038 -0800
|
---|
[c822ddc] | 155 | @@ -1615,10 +1615,11 @@
|
---|
| 156 | {
|
---|
| 157 | int *ret;
|
---|
| 158 |
|
---|
| 159 | - ret = (int *)xmalloc (3 * sizeof (int));
|
---|
| 160 | + ret = (int *)xmalloc (4 * sizeof (int));
|
---|
| 161 | ret[0] = last_read_token;
|
---|
| 162 | ret[1] = token_before_that;
|
---|
| 163 | ret[2] = two_tokens_ago;
|
---|
| 164 | + ret[3] = current_token;
|
---|
| 165 | return ret;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | @@ -1631,6 +1632,7 @@
|
---|
| 169 | last_read_token = ts[0];
|
---|
| 170 | token_before_that = ts[1];
|
---|
| 171 | two_tokens_ago = ts[2];
|
---|
| 172 | + current_token = ts[3];
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | /*
|
---|
| 176 | @@ -2668,6 +2670,7 @@
|
---|
| 177 | FREE (word_desc_to_read);
|
---|
| 178 | word_desc_to_read = (WORD_DESC *)NULL;
|
---|
| 179 |
|
---|
| 180 | + current_token = '\n'; /* XXX */
|
---|
| 181 | last_read_token = '\n';
|
---|
| 182 | token_to_read = '\n';
|
---|
| 183 | }
|
---|
| 184 | @@ -2915,6 +2918,7 @@
|
---|
| 185 | #define P_DQUOTE 0x04
|
---|
| 186 | #define P_COMMAND 0x08 /* parsing a command, so look for comments */
|
---|
| 187 | #define P_BACKQUOTE 0x10 /* parsing a backquoted command substitution */
|
---|
| 188 | +#define P_ARRAYSUB 0x20 /* parsing a [...] array subscript for assignment */
|
---|
| 189 |
|
---|
| 190 | /* Lexical state while parsing a grouping construct or $(...). */
|
---|
| 191 | #define LEX_WASDOL 0x001
|
---|
| 192 | @@ -3129,6 +3133,8 @@
|
---|
| 193 | APPEND_NESTRET ();
|
---|
| 194 | FREE (nestret);
|
---|
| 195 | }
|
---|
| 196 | + else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
|
---|
| 197 | + goto parse_dollar_word;
|
---|
| 198 | }
|
---|
| 199 | /* Parse an old-style command substitution within double quotes as a
|
---|
| 200 | single word. */
|
---|
| 201 | @@ -3145,6 +3151,7 @@
|
---|
| 202 | else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
|
---|
| 203 | /* check for $(), $[], or ${} inside quoted string. */
|
---|
| 204 | {
|
---|
| 205 | +parse_dollar_word:
|
---|
| 206 | if (open == ch) /* undo previous increment */
|
---|
| 207 | count--;
|
---|
| 208 | if (ch == '(') /* ) */
|
---|
| 209 | @@ -3306,7 +3313,7 @@
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | /* Meta-characters that can introduce a reserved word. Not perfect yet. */
|
---|
| 213 | - if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && shellmeta(ch))
|
---|
| 214 | + if MBTEST((tflags & LEX_PASSNEXT) == 0 && (tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && shellmeta(ch))
|
---|
| 215 | {
|
---|
| 216 | /* Add this character. */
|
---|
| 217 | RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
|
---|
| 218 | @@ -3394,8 +3401,11 @@
|
---|
| 219 | }
|
---|
| 220 | else
|
---|
| 221 | shell_ungetc (peekc);
|
---|
| 222 | - tflags |= LEX_HEREDELIM;
|
---|
| 223 | - lex_firstind = -1;
|
---|
| 224 | + if (peekc != '<')
|
---|
| 225 | + {
|
---|
| 226 | + tflags |= LEX_HEREDELIM;
|
---|
| 227 | + lex_firstind = -1;
|
---|
| 228 | + }
|
---|
| 229 | continue;
|
---|
| 230 | }
|
---|
| 231 | else
|
---|
| 232 | @@ -4248,7 +4258,7 @@
|
---|
| 233 | ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
|
---|
| 234 | (token_index == 0 && (parser_state&PST_COMPASSIGN))))
|
---|
| 235 | {
|
---|
| 236 | - ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
|
---|
| 237 | + ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
|
---|
| 238 | if (ttok == &matched_pair_error)
|
---|
| 239 | return -1; /* Bail immediately. */
|
---|
| 240 | RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
|
---|
| 241 | @@ -4449,6 +4459,7 @@
|
---|
| 242 | case '}': /* XXX */
|
---|
| 243 | case AND_AND:
|
---|
| 244 | case BANG:
|
---|
| 245 | + case BAR_AND:
|
---|
| 246 | case DO:
|
---|
| 247 | case DONE:
|
---|
| 248 | case ELIF:
|
---|
| 249 | diff -Naur bash-4.0.orig/pcomplete.c bash-4.0/pcomplete.c
|
---|
| 250 | --- bash-4.0.orig/pcomplete.c 2009-02-01 14:12:31.000000000 -0800
|
---|
[7a39f29] | 251 | +++ bash-4.0/pcomplete.c 2009-03-02 12:37:07.367275038 -0800
|
---|
[c822ddc] | 252 | @@ -1032,6 +1032,7 @@
|
---|
| 253 | cmdlist = build_arg_list (funcname, text, lwords, cw);
|
---|
| 254 |
|
---|
| 255 | pps = &ps;
|
---|
| 256 | + save_parser_state (pps);
|
---|
| 257 | begin_unwind_frame ("gen-shell-function-matches");
|
---|
| 258 | add_unwind_protect (restore_parser_state, (char *)pps);
|
---|
| 259 | add_unwind_protect (dispose_words, (char *)cmdlist);
|
---|
| 260 | diff -Naur bash-4.0.orig/subst.c bash-4.0/subst.c
|
---|
| 261 | --- bash-4.0.orig/subst.c 2009-01-28 11:34:12.000000000 -0800
|
---|
[7a39f29] | 262 | +++ bash-4.0/subst.c 2009-03-02 12:37:07.371275038 -0800
|
---|
[c822ddc] | 263 | @@ -222,6 +222,7 @@
|
---|
| 264 | static int skip_double_quoted __P((char *, size_t, int));
|
---|
| 265 | static char *extract_delimited_string __P((char *, int *, char *, char *, char *, int));
|
---|
| 266 | static char *extract_dollar_brace_string __P((char *, int *, int, int));
|
---|
| 267 | +static int skip_matched_pair __P((const char *, int, int, int, int));
|
---|
| 268 |
|
---|
| 269 | static char *pos_params __P((char *, int, int, int));
|
---|
| 270 |
|
---|
| 271 | @@ -1374,6 +1375,107 @@
|
---|
| 272 |
|
---|
| 273 | #define CQ_RETURN(x) do { no_longjmp_on_fatal_error = 0; return (x); } while (0)
|
---|
| 274 |
|
---|
| 275 | +/* This function assumes s[i] == open; returns with s[ret] == close; used to
|
---|
| 276 | + parse array subscripts. FLAGS currently unused. */
|
---|
| 277 | +static int
|
---|
| 278 | +skip_matched_pair (string, start, open, close, flags)
|
---|
| 279 | + const char *string;
|
---|
| 280 | + int start, open, close, flags;
|
---|
| 281 | +{
|
---|
| 282 | + int i, pass_next, backq, si, c, count;
|
---|
| 283 | + size_t slen;
|
---|
| 284 | + char *temp, *ss;
|
---|
| 285 | + DECLARE_MBSTATE;
|
---|
| 286 | +
|
---|
| 287 | + slen = strlen (string + start) + start;
|
---|
| 288 | + no_longjmp_on_fatal_error = 1;
|
---|
| 289 | +
|
---|
| 290 | + i = start + 1; /* skip over leading bracket */
|
---|
| 291 | + count = 1;
|
---|
| 292 | + pass_next = backq = 0;
|
---|
| 293 | + ss = (char *)string;
|
---|
| 294 | + while (c = string[i])
|
---|
| 295 | + {
|
---|
| 296 | + if (pass_next)
|
---|
| 297 | + {
|
---|
| 298 | + pass_next = 0;
|
---|
| 299 | + if (c == 0)
|
---|
| 300 | + CQ_RETURN(i);
|
---|
| 301 | + ADVANCE_CHAR (string, slen, i);
|
---|
| 302 | + continue;
|
---|
| 303 | + }
|
---|
| 304 | + else if (c == '\\')
|
---|
| 305 | + {
|
---|
| 306 | + pass_next = 1;
|
---|
| 307 | + i++;
|
---|
| 308 | + continue;
|
---|
| 309 | + }
|
---|
| 310 | + else if (backq)
|
---|
| 311 | + {
|
---|
| 312 | + if (c == '`')
|
---|
| 313 | + backq = 0;
|
---|
| 314 | + ADVANCE_CHAR (string, slen, i);
|
---|
| 315 | + continue;
|
---|
| 316 | + }
|
---|
| 317 | + else if (c == '`')
|
---|
| 318 | + {
|
---|
| 319 | + backq = 1;
|
---|
| 320 | + i++;
|
---|
| 321 | + continue;
|
---|
| 322 | + }
|
---|
| 323 | + else if (c == open)
|
---|
| 324 | + {
|
---|
| 325 | + count++;
|
---|
| 326 | + i++;
|
---|
| 327 | + continue;
|
---|
| 328 | + }
|
---|
| 329 | + else if (c == close)
|
---|
| 330 | + {
|
---|
| 331 | + count--;
|
---|
| 332 | + if (count == 0)
|
---|
| 333 | + break;
|
---|
| 334 | + i++;
|
---|
| 335 | + continue;
|
---|
| 336 | + }
|
---|
| 337 | + else if (c == '\'' || c == '"')
|
---|
| 338 | + {
|
---|
| 339 | + i = (c == '\'') ? skip_single_quoted (ss, slen, ++i)
|
---|
| 340 | + : skip_double_quoted (ss, slen, ++i);
|
---|
| 341 | + /* no increment, the skip functions increment past the closing quote. */
|
---|
| 342 | + }
|
---|
| 343 | + else if (c == '$' && (string[i+1] == LPAREN || string[i+1] == LBRACE))
|
---|
| 344 | + {
|
---|
| 345 | + si = i + 2;
|
---|
| 346 | + if (string[si] == '\0')
|
---|
| 347 | + CQ_RETURN(si);
|
---|
| 348 | +
|
---|
| 349 | + if (string[i+1] == LPAREN)
|
---|
| 350 | + temp = extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */
|
---|
| 351 | + else
|
---|
| 352 | + temp = extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC);
|
---|
| 353 | + i = si;
|
---|
| 354 | + if (string[i] == '\0') /* don't increment i past EOS in loop */
|
---|
| 355 | + break;
|
---|
| 356 | + i++;
|
---|
| 357 | + continue;
|
---|
| 358 | + }
|
---|
| 359 | + else
|
---|
| 360 | + ADVANCE_CHAR (string, slen, i);
|
---|
| 361 | + }
|
---|
| 362 | +
|
---|
| 363 | + CQ_RETURN(i);
|
---|
| 364 | +}
|
---|
| 365 | +
|
---|
| 366 | +#if defined (ARRAY_VARS)
|
---|
| 367 | +int
|
---|
| 368 | +skipsubscript (string, start)
|
---|
| 369 | + const char *string;
|
---|
| 370 | + int start;
|
---|
| 371 | +{
|
---|
| 372 | + return (skip_matched_pair (string, start, '[', ']', 0));
|
---|
| 373 | +}
|
---|
| 374 | +#endif
|
---|
| 375 | +
|
---|
| 376 | /* Skip characters in STRING until we find a character in DELIMS, and return
|
---|
| 377 | the index of that character. START is the index into string at which we
|
---|
| 378 | begin. This is similar in spirit to strpbrk, but it returns an index into
|
---|
| 379 |
|
---|