bash44-012.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. From https://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-012
  2. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  3. BASH PATCH REPORT
  4. =================
  5. Bash-Release: 4.4
  6. Patch-ID: bash44-012
  7. Bug-Reported-by: Clark Wang <dearvoid@gmail.com>
  8. Bug-Reference-ID: <CADv8-ojttPUFOZXqbjsvy83LfaJtQKZ5qejGdF6j0VJ3vtrYOA@mail.gmail.com>
  9. Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2016-11/msg00106.html
  10. Bug-Description:
  11. When -N is used, the input is not supposed to be split using $IFS, but
  12. leading and trailing IFS whitespace was still removed.
  13. Patch (apply with `patch -p0'):
  14. *** bash-4.4-patched/subst.c 2017-01-20 14:22:01.000000000 -0500
  15. --- b/subst.c 2017-01-25 13:43:22.000000000 -0500
  16. ***************
  17. *** 2826,2834 ****
  18. /* Parse a single word from STRING, using SEPARATORS to separate fields.
  19. ENDPTR is set to the first character after the word. This is used by
  20. ! the `read' builtin. This is never called with SEPARATORS != $IFS;
  21. ! it should be simplified.
  22. XXX - this function is very similar to list_string; they should be
  23. combined - XXX */
  24. char *
  25. get_word_from_string (stringp, separators, endptr)
  26. --- b/2826,2838 ----
  27. /* Parse a single word from STRING, using SEPARATORS to separate fields.
  28. ENDPTR is set to the first character after the word. This is used by
  29. ! the `read' builtin.
  30. !
  31. ! This is never called with SEPARATORS != $IFS, and takes advantage of that.
  32. XXX - this function is very similar to list_string; they should be
  33. combined - XXX */
  34. +
  35. + #define islocalsep(c) (local_cmap[(unsigned char)(c)] != 0)
  36. +
  37. char *
  38. get_word_from_string (stringp, separators, endptr)
  39. ***************
  40. *** 2838,2841 ****
  41. --- b/2842,2846 ----
  42. char *current_word;
  43. int sindex, sh_style_split, whitesep, xflags;
  44. + unsigned char local_cmap[UCHAR_MAX+1]; /* really only need single-byte chars here */
  45. size_t slen;
  46. ***************
  47. *** 2847,2854 ****
  48. separators[2] == '\n' &&
  49. separators[3] == '\0';
  50. ! for (xflags = 0, s = ifs_value; s && *s; s++)
  51. {
  52. if (*s == CTLESC) xflags |= SX_NOCTLESC;
  53. if (*s == CTLNUL) xflags |= SX_NOESCCTLNUL;
  54. }
  55. --- b/2852,2861 ----
  56. separators[2] == '\n' &&
  57. separators[3] == '\0';
  58. ! memset (local_cmap, '\0', sizeof (local_cmap));
  59. ! for (xflags = 0, s = separators; s && *s; s++)
  60. {
  61. if (*s == CTLESC) xflags |= SX_NOCTLESC;
  62. if (*s == CTLNUL) xflags |= SX_NOESCCTLNUL;
  63. + local_cmap[(unsigned char)*s] = 1; /* local charmap of separators */
  64. }
  65. ***************
  66. *** 2857,2864 ****
  67. /* Remove sequences of whitespace at the beginning of STRING, as
  68. ! long as those characters appear in IFS. */
  69. ! if (sh_style_split || !separators || !*separators)
  70. {
  71. ! for (; *s && spctabnl (*s) && isifs (*s); s++);
  72. /* If the string is nothing but whitespace, update it and return. */
  73. --- b/2864,2872 ----
  74. /* Remove sequences of whitespace at the beginning of STRING, as
  75. ! long as those characters appear in SEPARATORS. This happens if
  76. ! SEPARATORS == $' \t\n' or if IFS is unset. */
  77. ! if (sh_style_split || separators == 0)
  78. {
  79. ! for (; *s && spctabnl (*s) && islocalsep (*s); s++);
  80. /* If the string is nothing but whitespace, update it and return. */
  81. ***************
  82. *** 2879,2885 ****
  83. This obeys the field splitting rules in Posix.2. */
  84. sindex = 0;
  85. ! /* Don't need string length in ADVANCE_CHAR or string_extract_verbatim
  86. ! unless multibyte chars are possible. */
  87. ! slen = (MB_CUR_MAX > 1) ? STRLEN (s) : 1;
  88. current_word = string_extract_verbatim (s, slen, &sindex, separators, xflags);
  89. --- b/2887,2893 ----
  90. This obeys the field splitting rules in Posix.2. */
  91. sindex = 0;
  92. ! /* Don't need string length in ADVANCE_CHAR unless multibyte chars are
  93. ! possible, but need it in string_extract_verbatim for bounds checking */
  94. ! slen = STRLEN (s);
  95. current_word = string_extract_verbatim (s, slen, &sindex, separators, xflags);
  96. ***************
  97. *** 2900,2904 ****
  98. /* Now skip sequences of space, tab, or newline characters if they are
  99. in the list of separators. */
  100. ! while (s[sindex] && spctabnl (s[sindex]) && isifs (s[sindex]))
  101. sindex++;
  102. --- b/2908,2912 ----
  103. /* Now skip sequences of space, tab, or newline characters if they are
  104. in the list of separators. */
  105. ! while (s[sindex] && spctabnl (s[sindex]) && islocalsep (s[sindex]))
  106. sindex++;
  107. ***************
  108. *** 2907,2916 ****
  109. delimiter, not a separate delimiter that would result in an empty field.
  110. Look at POSIX.2, 3.6.5, (3)(b). */
  111. ! if (s[sindex] && whitesep && isifs (s[sindex]) && !spctabnl (s[sindex]))
  112. {
  113. sindex++;
  114. /* An IFS character that is not IFS white space, along with any adjacent
  115. IFS white space, shall delimit a field. */
  116. ! while (s[sindex] && spctabnl (s[sindex]) && isifs (s[sindex]))
  117. sindex++;
  118. }
  119. --- b/2915,2924 ----
  120. delimiter, not a separate delimiter that would result in an empty field.
  121. Look at POSIX.2, 3.6.5, (3)(b). */
  122. ! if (s[sindex] && whitesep && islocalsep (s[sindex]) && !spctabnl (s[sindex]))
  123. {
  124. sindex++;
  125. /* An IFS character that is not IFS white space, along with any adjacent
  126. IFS white space, shall delimit a field. */
  127. ! while (s[sindex] && spctabnl (s[sindex]) && islocalsep(s[sindex]))
  128. sindex++;
  129. }
  130. *** bash-4.4/patchlevel.h 2016-06-22 14:51:03.000000000 -0400
  131. --- b/patchlevel.h 2016-10-01 11:01:28.000000000 -0400
  132. ***************
  133. *** 26,30 ****
  134. looks for to find the patch level (for the sccs version string). */
  135. ! #define PATCHLEVEL 11
  136. #endif /* _PATCHLEVEL_H_ */
  137. --- b/26,30 ----
  138. looks for to find the patch level (for the sccs version string). */
  139. ! #define PATCHLEVEL 12
  140. #endif /* _PATCHLEVEL_H_ */