|
|
9014c4 |
From bc007799f0e1362100375bb95d952d28de4c62fb Mon Sep 17 00:00:00 2001
|
|
|
9014c4 |
From: Chet Ramey <chet.ramey@case.edu>
|
|
|
9014c4 |
Date: Fri, 27 Jan 2017 11:25:44 -0500
|
|
|
9014c4 |
Subject: [PATCH] Bash-4.4 patch 12
|
|
|
9014c4 |
|
|
|
9014c4 |
---
|
|
|
9014c4 |
patchlevel.h | 2 +-
|
|
|
9014c4 |
subst.c | 32 ++++++++++++++++++++------------
|
|
|
9014c4 |
2 files changed, 21 insertions(+), 13 deletions(-)
|
|
|
9014c4 |
|
|
|
9014c4 |
diff --git a/patchlevel.h b/patchlevel.h
|
|
|
9014c4 |
index 772676c..93dbe0d 100644
|
|
|
9014c4 |
--- a/patchlevel.h
|
|
|
9014c4 |
+++ b/patchlevel.h
|
|
|
9014c4 |
@@ -25,6 +25,6 @@
|
|
|
9014c4 |
regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
|
|
|
9014c4 |
looks for to find the patch level (for the sccs version string). */
|
|
|
9014c4 |
|
|
|
9014c4 |
-#define PATCHLEVEL 11
|
|
|
9014c4 |
+#define PATCHLEVEL 12
|
|
|
9014c4 |
|
|
|
9014c4 |
#endif /* _PATCHLEVEL_H_ */
|
|
|
9014c4 |
diff --git a/subst.c b/subst.c
|
|
|
9014c4 |
index 027a13e..dbf0157 100644
|
|
|
9014c4 |
--- a/subst.c
|
|
|
9014c4 |
+++ b/subst.c
|
|
|
9014c4 |
@@ -2825,11 +2825,15 @@ list_string (string, separators, quoted)
|
|
|
9014c4 |
|
|
|
9014c4 |
/* Parse a single word from STRING, using SEPARATORS to separate fields.
|
|
|
9014c4 |
ENDPTR is set to the first character after the word. This is used by
|
|
|
9014c4 |
- the `read' builtin. This is never called with SEPARATORS != $IFS;
|
|
|
9014c4 |
- it should be simplified.
|
|
|
9014c4 |
+ the `read' builtin.
|
|
|
9014c4 |
+
|
|
|
9014c4 |
+ This is never called with SEPARATORS != $IFS, and takes advantage of that.
|
|
|
9014c4 |
|
|
|
9014c4 |
XXX - this function is very similar to list_string; they should be
|
|
|
9014c4 |
combined - XXX */
|
|
|
9014c4 |
+
|
|
|
9014c4 |
+#define islocalsep(c) (local_cmap[(unsigned char)(c)] != 0)
|
|
|
9014c4 |
+
|
|
|
9014c4 |
char *
|
|
|
9014c4 |
get_word_from_string (stringp, separators, endptr)
|
|
|
9014c4 |
char **stringp, *separators, **endptr;
|
|
|
9014c4 |
@@ -2837,6 +2841,7 @@ get_word_from_string (stringp, separators, endptr)
|
|
|
9014c4 |
register char *s;
|
|
|
9014c4 |
char *current_word;
|
|
|
9014c4 |
int sindex, sh_style_split, whitesep, xflags;
|
|
|
9014c4 |
+ unsigned char local_cmap[UCHAR_MAX+1]; /* really only need single-byte chars here */
|
|
|
9014c4 |
size_t slen;
|
|
|
9014c4 |
|
|
|
9014c4 |
if (!stringp || !*stringp || !**stringp)
|
|
|
9014c4 |
@@ -2846,20 +2851,23 @@ get_word_from_string (stringp, separators, endptr)
|
|
|
9014c4 |
separators[1] == '\t' &&
|
|
|
9014c4 |
separators[2] == '\n' &&
|
|
|
9014c4 |
separators[3] == '\0';
|
|
|
9014c4 |
- for (xflags = 0, s = ifs_value; s && *s; s++)
|
|
|
9014c4 |
+ memset (local_cmap, '\0', sizeof (local_cmap));
|
|
|
9014c4 |
+ for (xflags = 0, s = separators; s && *s; s++)
|
|
|
9014c4 |
{
|
|
|
9014c4 |
if (*s == CTLESC) xflags |= SX_NOCTLESC;
|
|
|
9014c4 |
if (*s == CTLNUL) xflags |= SX_NOESCCTLNUL;
|
|
|
9014c4 |
+ local_cmap[(unsigned char)*s] = 1; /* local charmap of separators */
|
|
|
9014c4 |
}
|
|
|
9014c4 |
|
|
|
9014c4 |
s = *stringp;
|
|
|
9014c4 |
slen = 0;
|
|
|
9014c4 |
|
|
|
9014c4 |
/* Remove sequences of whitespace at the beginning of STRING, as
|
|
|
9014c4 |
- long as those characters appear in IFS. */
|
|
|
9014c4 |
- if (sh_style_split || !separators || !*separators)
|
|
|
9014c4 |
+ long as those characters appear in SEPARATORS. This happens if
|
|
|
9014c4 |
+ SEPARATORS == $' \t\n' or if IFS is unset. */
|
|
|
9014c4 |
+ if (sh_style_split || separators == 0)
|
|
|
9014c4 |
{
|
|
|
9014c4 |
- for (; *s && spctabnl (*s) && isifs (*s); s++);
|
|
|
9014c4 |
+ for (; *s && spctabnl (*s) && islocalsep (*s); s++);
|
|
|
9014c4 |
|
|
|
9014c4 |
/* If the string is nothing but whitespace, update it and return. */
|
|
|
9014c4 |
if (!*s)
|
|
|
9014c4 |
@@ -2878,9 +2886,9 @@ get_word_from_string (stringp, separators, endptr)
|
|
|
9014c4 |
|
|
|
9014c4 |
This obeys the field splitting rules in Posix.2. */
|
|
|
9014c4 |
sindex = 0;
|
|
|
9014c4 |
- /* Don't need string length in ADVANCE_CHAR or string_extract_verbatim
|
|
|
9014c4 |
- unless multibyte chars are possible. */
|
|
|
9014c4 |
- slen = (MB_CUR_MAX > 1) ? STRLEN (s) : 1;
|
|
|
9014c4 |
+ /* Don't need string length in ADVANCE_CHAR unless multibyte chars are
|
|
|
9014c4 |
+ possible, but need it in string_extract_verbatim for bounds checking */
|
|
|
9014c4 |
+ slen = STRLEN (s);
|
|
|
9014c4 |
current_word = string_extract_verbatim (s, slen, &sindex, separators, xflags);
|
|
|
9014c4 |
|
|
|
9014c4 |
/* Set ENDPTR to the first character after the end of the word. */
|
|
|
9014c4 |
@@ -2899,19 +2907,19 @@ get_word_from_string (stringp, separators, endptr)
|
|
|
9014c4 |
|
|
|
9014c4 |
/* Now skip sequences of space, tab, or newline characters if they are
|
|
|
9014c4 |
in the list of separators. */
|
|
|
9014c4 |
- while (s[sindex] && spctabnl (s[sindex]) && isifs (s[sindex]))
|
|
|
9014c4 |
+ while (s[sindex] && spctabnl (s[sindex]) && islocalsep (s[sindex]))
|
|
|
9014c4 |
sindex++;
|
|
|
9014c4 |
|
|
|
9014c4 |
/* If the first separator was IFS whitespace and the current character is
|
|
|
9014c4 |
a non-whitespace IFS character, it should be part of the current field
|
|
|
9014c4 |
delimiter, not a separate delimiter that would result in an empty field.
|
|
|
9014c4 |
Look at POSIX.2, 3.6.5, (3)(b). */
|
|
|
9014c4 |
- if (s[sindex] && whitesep && isifs (s[sindex]) && !spctabnl (s[sindex]))
|
|
|
9014c4 |
+ if (s[sindex] && whitesep && islocalsep (s[sindex]) && !spctabnl (s[sindex]))
|
|
|
9014c4 |
{
|
|
|
9014c4 |
sindex++;
|
|
|
9014c4 |
/* An IFS character that is not IFS white space, along with any adjacent
|
|
|
9014c4 |
IFS white space, shall delimit a field. */
|
|
|
9014c4 |
- while (s[sindex] && spctabnl (s[sindex]) && isifs (s[sindex]))
|
|
|
9014c4 |
+ while (s[sindex] && spctabnl (s[sindex]) && islocalsep(s[sindex]))
|
|
|
9014c4 |
sindex++;
|
|
|
9014c4 |
}
|
|
|
9014c4 |
|
|
|
9014c4 |
--
|
|
|
9014c4 |
2.9.3
|
|
|
9014c4 |
|