You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.3 KiB

  1. BASH PATCH REPORT
  2. =================
  3. Bash-Release: 4.3
  4. Patch-ID: bash43-016
  5. Bug-Reported-by: Pierre Gaston <pierre.gaston@gmail.com>
  6. Bug-Reference-ID: <CAPSX3sTCD61k1VQLJ5r-LWzEt+e7Xc-fxXmwn2u8EA5gJJej8Q@mail.gmail.com>
  7. Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2014-04/msg00100.html
  8. Bug-Description:
  9. An extended glob pattern containing a slash (`/') causes the globbing code
  10. to misinterpret it as a directory separator.
  11. Patch (apply with `patch -p0'):
  12. --- a/lib/glob/glob.c
  13. +++ b/lib/glob/glob.c
  14. @@ -123,6 +123,8 @@ static char **glob_dir_to_array __P((cha
  15. extern char *glob_patscan __P((char *, char *, int));
  16. extern wchar_t *glob_patscan_wc __P((wchar_t *, wchar_t *, int));
  17. +extern char *glob_dirscan __P((char *, int));
  18. +
  19. /* Compile `glob_loop.c' for single-byte characters. */
  20. #define CHAR unsigned char
  21. #define INT int
  22. @@ -187,6 +189,9 @@ extglob_skipname (pat, dname, flags)
  23. se = pp + strlen (pp) - 1; /* end of string */
  24. pe = glob_patscan (pp, se, 0); /* end of extglob pattern (( */
  25. /* we should check for invalid extglob pattern here */
  26. + if (pe == 0)
  27. + return 0;
  28. +
  29. /* if pe != se we have more of the pattern at the end of the extglob
  30. pattern. Check the easy case first ( */
  31. if (pe == se && *pe == ')' && (t = strchr (pp, '|')) == 0)
  32. @@ -1015,7 +1020,7 @@ glob_filename (pathname, flags)
  33. {
  34. char **result;
  35. unsigned int result_size;
  36. - char *directory_name, *filename, *dname;
  37. + char *directory_name, *filename, *dname, *fn;
  38. unsigned int directory_len;
  39. int free_dirname; /* flag */
  40. int dflags;
  41. @@ -1031,6 +1036,18 @@ glob_filename (pathname, flags)
  42. /* Find the filename. */
  43. filename = strrchr (pathname, '/');
  44. +#if defined (EXTENDED_GLOB)
  45. + if (filename && extended_glob)
  46. + {
  47. + fn = glob_dirscan (pathname, '/');
  48. +#if DEBUG_MATCHING
  49. + if (fn != filename)
  50. + fprintf (stderr, "glob_filename: glob_dirscan: fn (%s) != filename (%s)\n", fn ? fn : "(null)", filename);
  51. +#endif
  52. + filename = fn;
  53. + }
  54. +#endif
  55. +
  56. if (filename == NULL)
  57. {
  58. filename = pathname;
  59. --- a/lib/glob/gmisc.c
  60. +++ b/lib/glob/gmisc.c
  61. @@ -42,6 +42,8 @@
  62. #define WLPAREN L'('
  63. #define WRPAREN L')'
  64. +extern char *glob_patscan __P((char *, char *, int));
  65. +
  66. /* Return 1 of the first character of WSTRING could match the first
  67. character of pattern WPAT. Wide character version. */
  68. int
  69. @@ -375,3 +377,34 @@ bad_bracket:
  70. return matlen;
  71. }
  72. +
  73. +/* Skip characters in PAT and return the final occurrence of DIRSEP. This
  74. + is only called when extended_glob is set, so we have to skip over extglob
  75. + patterns x(...) */
  76. +char *
  77. +glob_dirscan (pat, dirsep)
  78. + char *pat;
  79. + int dirsep;
  80. +{
  81. + char *p, *d, *pe, *se;
  82. +
  83. + d = pe = se = 0;
  84. + for (p = pat; p && *p; p++)
  85. + {
  86. + if (extglob_pattern_p (p))
  87. + {
  88. + if (se == 0)
  89. + se = p + strlen (p) - 1;
  90. + pe = glob_patscan (p + 2, se, 0);
  91. + if (pe == 0)
  92. + continue;
  93. + else if (*pe == 0)
  94. + break;
  95. + p = pe - 1; /* will do increment above */
  96. + continue;
  97. + }
  98. + if (*p == dirsep)
  99. + d = p;
  100. + }
  101. + return d;
  102. +}
  103. --- a/patchlevel.h
  104. +++ b/patchlevel.h
  105. @@ -25,6 +25,6 @@
  106. regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
  107. looks for to find the patch level (for the sccs version string). */
  108. -#define PATCHLEVEL 15
  109. +#define PATCHLEVEL 16
  110. #endif /* _PATCHLEVEL_H_ */