Merge pull request #4732 from hashashin/bash-4.4.12
[feed/packages.git] / utils / bash / patches / 112-upstream-bash44-012.patch
1 Index: bash-4.4/patchlevel.h
2 ===================================================================
3 --- bash-4.4.orig/patchlevel.h
4 +++ bash-4.4/patchlevel.h
5 @@ -25,6 +25,6 @@
6 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
7 looks for to find the patch level (for the sccs version string). */
8
9 -#define PATCHLEVEL 11
10 +#define PATCHLEVEL 12
11
12 #endif /* _PATCHLEVEL_H_ */
13 Index: bash-4.4/subst.c
14 ===================================================================
15 --- bash-4.4.orig/subst.c
16 +++ bash-4.4/subst.c
17 @@ -2825,11 +2825,15 @@ list_string (string, separators, quoted)
18
19 /* Parse a single word from STRING, using SEPARATORS to separate fields.
20 ENDPTR is set to the first character after the word. This is used by
21 - the `read' builtin. This is never called with SEPARATORS != $IFS;
22 - it should be simplified.
23 + the `read' builtin.
24 +
25 + This is never called with SEPARATORS != $IFS, and takes advantage of that.
26
27 XXX - this function is very similar to list_string; they should be
28 combined - XXX */
29 +
30 +#define islocalsep(c) (local_cmap[(unsigned char)(c)] != 0)
31 +
32 char *
33 get_word_from_string (stringp, separators, endptr)
34 char **stringp, *separators, **endptr;
35 @@ -2837,6 +2841,7 @@ get_word_from_string (stringp, separator
36 register char *s;
37 char *current_word;
38 int sindex, sh_style_split, whitesep, xflags;
39 + unsigned char local_cmap[UCHAR_MAX+1]; /* really only need single-byte chars here */
40 size_t slen;
41
42 if (!stringp || !*stringp || !**stringp)
43 @@ -2846,20 +2851,23 @@ get_word_from_string (stringp, separator
44 separators[1] == '\t' &&
45 separators[2] == '\n' &&
46 separators[3] == '\0';
47 - for (xflags = 0, s = ifs_value; s && *s; s++)
48 + memset (local_cmap, '\0', sizeof (local_cmap));
49 + for (xflags = 0, s = separators; s && *s; s++)
50 {
51 if (*s == CTLESC) xflags |= SX_NOCTLESC;
52 if (*s == CTLNUL) xflags |= SX_NOESCCTLNUL;
53 + local_cmap[(unsigned char)*s] = 1; /* local charmap of separators */
54 }
55
56 s = *stringp;
57 slen = 0;
58
59 /* Remove sequences of whitespace at the beginning of STRING, as
60 - long as those characters appear in IFS. */
61 - if (sh_style_split || !separators || !*separators)
62 + long as those characters appear in SEPARATORS. This happens if
63 + SEPARATORS == $' \t\n' or if IFS is unset. */
64 + if (sh_style_split || separators == 0)
65 {
66 - for (; *s && spctabnl (*s) && isifs (*s); s++);
67 + for (; *s && spctabnl (*s) && islocalsep (*s); s++);
68
69 /* If the string is nothing but whitespace, update it and return. */
70 if (!*s)
71 @@ -2878,9 +2886,9 @@ get_word_from_string (stringp, separator
72
73 This obeys the field splitting rules in Posix.2. */
74 sindex = 0;
75 - /* Don't need string length in ADVANCE_CHAR or string_extract_verbatim
76 - unless multibyte chars are possible. */
77 - slen = (MB_CUR_MAX > 1) ? STRLEN (s) : 1;
78 + /* Don't need string length in ADVANCE_CHAR unless multibyte chars are
79 + possible, but need it in string_extract_verbatim for bounds checking */
80 + slen = STRLEN (s);
81 current_word = string_extract_verbatim (s, slen, &sindex, separators, xflags);
82
83 /* Set ENDPTR to the first character after the end of the word. */
84 @@ -2899,19 +2907,19 @@ get_word_from_string (stringp, separator
85
86 /* Now skip sequences of space, tab, or newline characters if they are
87 in the list of separators. */
88 - while (s[sindex] && spctabnl (s[sindex]) && isifs (s[sindex]))
89 + while (s[sindex] && spctabnl (s[sindex]) && islocalsep (s[sindex]))
90 sindex++;
91
92 /* If the first separator was IFS whitespace and the current character is
93 a non-whitespace IFS character, it should be part of the current field
94 delimiter, not a separate delimiter that would result in an empty field.
95 Look at POSIX.2, 3.6.5, (3)(b). */
96 - if (s[sindex] && whitesep && isifs (s[sindex]) && !spctabnl (s[sindex]))
97 + if (s[sindex] && whitesep && islocalsep (s[sindex]) && !spctabnl (s[sindex]))
98 {
99 sindex++;
100 /* An IFS character that is not IFS white space, along with any adjacent
101 IFS white space, shall delimit a field. */
102 - while (s[sindex] && spctabnl (s[sindex]) && isifs (s[sindex]))
103 + while (s[sindex] && spctabnl (s[sindex]) && islocalsep(s[sindex]))
104 sindex++;
105 }
106