114-upstream-bash43-014.patch (3489B)
1 BASH PATCH REPORT 2 ================= 3 4 Bash-Release: 4.3 5 Patch-ID: bash43-014 6 7 Bug-Reported-by: Greg Wooledge <wooledg@eeg.ccf.org> 8 Bug-Reference-ID: <20140418202123.GB7660@eeg.ccf.org> 9 Bug-Reference-URL: http://lists.gnu.org/archive/html/help-bash/2014-04/msg00004.html 10 11 Bug-Description: 12 13 Under certain circumstances, $@ is expanded incorrectly in contexts where 14 word splitting is not performed. 15 16 Patch (apply with `patch -p0'): 17 --- a/subst.c 18 +++ b/subst.c 19 @@ -3248,8 +3248,10 @@ cond_expand_word (w, special) 20 if (w->word == 0 || w->word[0] == '\0') 21 return ((char *)NULL); 22 23 + expand_no_split_dollar_star = 1; 24 w->flags |= W_NOSPLIT2; 25 l = call_expand_word_internal (w, 0, 0, (int *)0, (int *)0); 26 + expand_no_split_dollar_star = 0; 27 if (l) 28 { 29 if (special == 0) /* LHS */ 30 @@ -7847,6 +7849,10 @@ param_expand (string, sindex, quoted, ex 31 We also want to make sure that splitting is done no matter what -- 32 according to POSIX.2, this expands to a list of the positional 33 parameters no matter what IFS is set to. */ 34 + /* XXX - what to do when in a context where word splitting is not 35 + performed? Even when IFS is not the default, posix seems to imply 36 + that we behave like unquoted $* ? Maybe we should use PF_NOSPLIT2 37 + here. */ 38 temp = string_list_dollar_at (list, (pflags & PF_ASSIGNRHS) ? (quoted|Q_DOUBLE_QUOTES) : quoted); 39 40 tflag |= W_DOLLARAT; 41 @@ -8816,6 +8822,7 @@ finished_with_string: 42 else 43 { 44 char *ifs_chars; 45 + char *tstring; 46 47 ifs_chars = (quoted_dollar_at || has_dollar_at) ? ifs_value : (char *)NULL; 48 49 @@ -8830,11 +8837,36 @@ finished_with_string: 50 regardless of what else has happened to IFS since the expansion. */ 51 if (split_on_spaces) 52 list = list_string (istring, " ", 1); /* XXX quoted == 1? */ 53 + /* If we have $@ (has_dollar_at != 0) and we are in a context where we 54 + don't want to split the result (W_NOSPLIT2), and we are not quoted, 55 + we have already separated the arguments with the first character of 56 + $IFS. In this case, we want to return a list with a single word 57 + with the separator possibly replaced with a space (it's what other 58 + shells seem to do). 59 + quoted_dollar_at is internal to this function and is set if we are 60 + passed an argument that is unquoted (quoted == 0) but we encounter a 61 + double-quoted $@ while expanding it. */ 62 + else if (has_dollar_at && quoted_dollar_at == 0 && ifs_chars && quoted == 0 && (word->flags & W_NOSPLIT2)) 63 + { 64 + /* Only split and rejoin if we have to */ 65 + if (*ifs_chars && *ifs_chars != ' ') 66 + { 67 + list = list_string (istring, *ifs_chars ? ifs_chars : " ", 1); 68 + tstring = string_list (list); 69 + } 70 + else 71 + tstring = istring; 72 + tword = make_bare_word (tstring); 73 + if (tstring != istring) 74 + free (tstring); 75 + goto set_word_flags; 76 + } 77 else if (has_dollar_at && ifs_chars) 78 list = list_string (istring, *ifs_chars ? ifs_chars : " ", 1); 79 else 80 { 81 tword = make_bare_word (istring); 82 +set_word_flags: 83 if ((quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)) || (quoted_state == WHOLLY_QUOTED)) 84 tword->flags |= W_QUOTED; 85 if (word->flags & W_ASSIGNMENT) 86 --- a/patchlevel.h 87 +++ b/patchlevel.h 88 @@ -25,6 +25,6 @@ 89 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh 90 looks for to find the patch level (for the sccs version string). */ 91 92 -#define PATCHLEVEL 13 93 +#define PATCHLEVEL 14 94 95 #endif /* _PATCHLEVEL_H_ */