7 Bug-Reported-by: Pierre Gaston <pierre.gaston@gmail.com>
8 Bug-Reference-ID: <CAPSX3sTCD61k1VQLJ5r-LWzEt+e7Xc-fxXmwn2u8EA5gJJej8Q@mail.gmail.com>
9 Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2014-04/msg00100.html
13 An extended glob pattern containing a slash (`/') causes the globbing code
14 to misinterpret it as a directory separator.
16 Patch (apply with `patch -p0'):
19 @@ -123,6 +123,8 @@ static char **glob_dir_to_array __P((cha
20 extern char *glob_patscan __P((char *, char *, int));
21 extern wchar_t *glob_patscan_wc __P((wchar_t *, wchar_t *, int));
23 +extern char *glob_dirscan __P((char *, int));
25 /* Compile `glob_loop.c' for single-byte characters. */
26 #define CHAR unsigned char
28 @@ -187,6 +189,9 @@ extglob_skipname (pat, dname, flags)
29 se = pp + strlen (pp) - 1; /* end of string */
30 pe = glob_patscan (pp, se, 0); /* end of extglob pattern (( */
31 /* we should check for invalid extglob pattern here */
35 /* if pe != se we have more of the pattern at the end of the extglob
36 pattern. Check the easy case first ( */
37 if (pe == se && *pe == ')' && (t = strchr (pp, '|')) == 0)
38 @@ -1015,7 +1020,7 @@ glob_filename (pathname, flags)
41 unsigned int result_size;
42 - char *directory_name, *filename, *dname;
43 + char *directory_name, *filename, *dname, *fn;
44 unsigned int directory_len;
45 int free_dirname; /* flag */
47 @@ -1031,6 +1036,18 @@ glob_filename (pathname, flags)
49 /* Find the filename. */
50 filename = strrchr (pathname, '/');
51 +#if defined (EXTENDED_GLOB)
52 + if (filename && extended_glob)
54 + fn = glob_dirscan (pathname, '/');
57 + fprintf (stderr, "glob_filename: glob_dirscan: fn (%s) != filename (%s)\n", fn ? fn : "(null)", filename);
66 --- a/lib/glob/gmisc.c
67 +++ b/lib/glob/gmisc.c
72 +extern char *glob_patscan __P((char *, char *, int));
74 /* Return 1 of the first character of WSTRING could match the first
75 character of pattern WPAT. Wide character version. */
77 @@ -375,3 +377,34 @@ bad_bracket:
82 +/* Skip characters in PAT and return the final occurrence of DIRSEP. This
83 + is only called when extended_glob is set, so we have to skip over extglob
86 +glob_dirscan (pat, dirsep)
90 + char *p, *d, *pe, *se;
93 + for (p = pat; p && *p; p++)
95 + if (extglob_pattern_p (p))
98 + se = p + strlen (p) - 1;
99 + pe = glob_patscan (p + 2, se, 0);
104 + p = pe - 1; /* will do increment above */
115 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
116 looks for to find the patch level (for the sccs version string). */
118 -#define PATCHLEVEL 15
119 +#define PATCHLEVEL 16
121 #endif /* _PATCHLEVEL_H_ */