This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH][BZ #10246] glob() with GLOB_NOCHECK is returning a modified pattern sometimes.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Sun, 20 Oct 2013 20:59:38 +0200
- Subject: [PATCH][BZ #10246] glob() with GLOB_NOCHECK is returning a modified pattern sometimes.
- Authentication-results: sourceware.org; auth=none
Hi,
This bug was caused joining cases when we do not check for errors or
directory exists. A fix is simple, jump to code that handles no matches.
[BZ #10246]
* posix/glob.c (glob): Return correct value when GLOB_NOCHECK
is specified.
diff --git a/posix/glob.c b/posix/glob.c
index 85237c2..1384bcc 100644
--- a/posix/glob.c
+++ b/posix/glob.c
@@ -958,8 +958,7 @@ glob (pattern, flags, errfunc, pglob)
struct_stat64 st64;
/* Return the directory if we don't check for error or if it exists. */
- if ((flags & GLOB_NOCHECK)
- || (((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0))
+ if ((((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0))
? ((*pglob->gl_stat) (dirname, &st) == 0
&& S_ISDIR (st.st_mode))
: (__stat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode)))))
@@ -1006,6 +1005,8 @@ glob (pattern, flags, errfunc, pglob)
return 0;
}
+ else if (flags & GLOB_NOCHECK)
+ goto no_matches;
/* Not found. */
return GLOB_NOMATCH;