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