Blame SOURCES/bash-4.4-patch-12.patch

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