108-upstream-bash43-008.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. BASH PATCH REPORT
  2. =================
  3. Bash-Release: 4.3
  4. Patch-ID: bash43-008
  5. Bug-Reported-by: Stephane Chazelas <stephane.chazelas@gmail.com>
  6. Bug-Reference-ID: <20140318135901.GB22158@chaz.gmail.com>
  7. Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2014-03/msg00098.html
  8. Bug-Description:
  9. Some extended glob patterns incorrectly matched filenames with a leading
  10. dot, regardless of the setting of the `dotglob' option.
  11. Patch (apply with `patch -p0'):
  12. --- a/lib/glob/gmisc.c
  13. +++ b/lib/glob/gmisc.c
  14. @@ -210,6 +210,7 @@ extglob_pattern_p (pat)
  15. case '+':
  16. case '!':
  17. case '@':
  18. + case '?':
  19. return (pat[1] == LPAREN);
  20. default:
  21. return 0;
  22. --- a/lib/glob/glob.c
  23. +++ b/lib/glob/glob.c
  24. @@ -179,42 +179,50 @@ extglob_skipname (pat, dname, flags)
  25. char *pat, *dname;
  26. int flags;
  27. {
  28. - char *pp, *pe, *t;
  29. - int n, r;
  30. + char *pp, *pe, *t, *se;
  31. + int n, r, negate;
  32. + negate = *pat == '!';
  33. pp = pat + 2;
  34. - pe = pp + strlen (pp) - 1; /*(*/
  35. - if (*pe != ')')
  36. - return 0;
  37. - if ((t = strchr (pp, '|')) == 0) /* easy case first */
  38. + se = pp + strlen (pp) - 1; /* end of string */
  39. + pe = glob_patscan (pp, se, 0); /* end of extglob pattern (( */
  40. + /* we should check for invalid extglob pattern here */
  41. + /* if pe != se we have more of the pattern at the end of the extglob
  42. + pattern. Check the easy case first ( */
  43. + if (pe == se && *pe == ')' && (t = strchr (pp, '|')) == 0)
  44. {
  45. *pe = '\0';
  46. +#if defined (HANDLE_MULTIBYTE)
  47. + r = mbskipname (pp, dname, flags);
  48. +#else
  49. r = skipname (pp, dname, flags); /*(*/
  50. +#endif
  51. *pe = ')';
  52. return r;
  53. }
  54. +
  55. + /* check every subpattern */
  56. while (t = glob_patscan (pp, pe, '|'))
  57. {
  58. n = t[-1];
  59. t[-1] = '\0';
  60. +#if defined (HANDLE_MULTIBYTE)
  61. + r = mbskipname (pp, dname, flags);
  62. +#else
  63. r = skipname (pp, dname, flags);
  64. +#endif
  65. t[-1] = n;
  66. if (r == 0) /* if any pattern says not skip, we don't skip */
  67. return r;
  68. pp = t;
  69. } /*(*/
  70. - if (pp == pe) /* glob_patscan might find end of pattern */
  71. + /* glob_patscan might find end of pattern */
  72. + if (pp == se)
  73. return r;
  74. - *pe = '\0';
  75. -# if defined (HANDLE_MULTIBYTE)
  76. - r = mbskipname (pp, dname, flags); /*(*/
  77. -# else
  78. - r = skipname (pp, dname, flags); /*(*/
  79. -# endif
  80. - *pe = ')';
  81. - return r;
  82. + /* but if it doesn't then we didn't match a leading dot */
  83. + return 0;
  84. }
  85. #endif
  86. @@ -277,20 +285,23 @@ wextglob_skipname (pat, dname, flags)
  87. int flags;
  88. {
  89. #if EXTENDED_GLOB
  90. - wchar_t *pp, *pe, *t, n;
  91. - int r;
  92. + wchar_t *pp, *pe, *t, n, *se;
  93. + int r, negate;
  94. + negate = *pat == L'!';
  95. pp = pat + 2;
  96. - pe = pp + wcslen (pp) - 1; /*(*/
  97. - if (*pe != L')')
  98. - return 0;
  99. - if ((t = wcschr (pp, L'|')) == 0)
  100. + se = pp + wcslen (pp) - 1; /*(*/
  101. + pe = glob_patscan_wc (pp, se, 0);
  102. +
  103. + if (pe == se && *pe == ')' && (t = wcschr (pp, L'|')) == 0)
  104. {
  105. *pe = L'\0';
  106. r = wchkname (pp, dname); /*(*/
  107. *pe = L')';
  108. return r;
  109. }
  110. +
  111. + /* check every subpattern */
  112. while (t = glob_patscan_wc (pp, pe, '|'))
  113. {
  114. n = t[-1];
  115. @@ -305,10 +316,8 @@ wextglob_skipname (pat, dname, flags)
  116. if (pp == pe) /* glob_patscan_wc might find end of pattern */
  117. return r;
  118. - *pe = L'\0';
  119. - r = wchkname (pp, dname); /*(*/
  120. - *pe = L')';
  121. - return r;
  122. + /* but if it doesn't then we didn't match a leading dot */
  123. + return 0;
  124. #else
  125. return (wchkname (pat, dname));
  126. #endif
  127. --- a/patchlevel.h
  128. +++ b/patchlevel.h
  129. @@ -25,6 +25,6 @@
  130. regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
  131. looks for to find the patch level (for the sccs version string). */
  132. -#define PATCHLEVEL 7
  133. +#define PATCHLEVEL 8
  134. #endif /* _PATCHLEVEL_H_ */