Bug#67921: Bug is indeed alive and well
I've just confirmed that glob() does exhibit problems dealing with escaped
*'s. Attached is the test program I used (adapted and enhanced from
Herbert's version to allow easier testing). I ran my tests in a directory
with the structure:
drwx------ hsteoh/hsteoh 0 2002-12-26 23:02:43 ./
-rw------- hsteoh/hsteoh 477 2002-12-26 23:02:11 ./globber.c
drwx------ hsteoh/hsteoh 0 2002-12-26 22:59:39 ./*/
-rw------- hsteoh/hsteoh 12 2002-12-26 22:51:03 ./*/starryfile
-rw------- hsteoh/hsteoh 1 2002-12-26 22:59:39 ./*/*
drwx------ hsteoh/hsteoh 0 2002-12-26 22:51:38 ./nasing/
-rwx------ hsteoh/hsteoh 5022 2002-12-26 23:02:14 ./globber
drwx------ hsteoh/hsteoh 0 2002-12-26 23:02:50 ./sasing/
-rw------- hsteoh/hsteoh 1 2002-12-26 23:02:50 ./sasing/chaching
Here are some test runs:
% ./globber '*'
Matched: *
Matched: globber
Matched: globber.c
Matched: nasing
Matched: sasing
% ./globber '\*'
Matched: *
% ./globber '*/'
Matched: */
Matched: nasing/
Matched: sasing/
% ./globber '\*/'
Matched: */
% ./globber '*/*'
Matched: */*
Matched: */starryfile
Matched: sasing/chaching
% ./globber '*/\*'
Matched: */*
So far so good. Now the bad news:
crystal:/tmp/glob 1428 % ./globber '\*/*'
No matches
crystal:/tmp/glob 1429 % ./globber '\*/\*'
No matches
These last two *should* match, based on the results of the previous cases.
However, it seems that glob() gets confused after seeing the first
instance of \* and somehow fails to handle subsequent *'s in a sane way
thereafter. I'll delve into the source a bit to find out why this is
happening.
T
--
Ph.D. = Permanent head Damage
#include <stdio.h>
#include <glob.h>
int main(int argc, char *argv[]) {
glob_t pglob;
int n, i;
if (argc != 2) {
printf("Syntax: globber <pattern>\n");
return 1;
}
n = glob(argv[1], 0, 0, &pglob);
switch (n) {
case 0: break;
case GLOB_NOMATCH: printf("No matches\n"); return 1;
default: printf("glob() error, rcode=%d\n",n); return 1;
}
for (i=0; i<pglob.gl_pathc; i++) {
printf("Matched: %s\n", pglob.gl_pathv[i]);
}
return 0;
}
Reply to: