This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH v3][BZ #10246] glob() with GLOB_NOCHECK is returning a modified pattern sometimes.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Mon, 21 Oct 2013 17:30:48 +0200
- Subject: [PATCH v3][BZ #10246] glob() with GLOB_NOCHECK is returning a modified pattern sometimes.
- Authentication-results: sourceware.org; auth=none
- References: <20131020185938 dot GA18659 at domone dot podge> <Pine dot LNX dot 4 dot 64 dot 1310211149180 dot 23978 at digraph dot polyomino dot org dot uk> <20131021130754 dot GA23902 at domone dot podge> <20131021131952 dot GA25167 at domone dot podge>
On Mon, Oct 21, 2013 at 03:19:52PM +0200, OndÅej BÃlka wrote:
> On Mon, Oct 21, 2013 at 03:07:54PM +0200, OndÅej BÃlka wrote:
> > On Mon, Oct 21, 2013 at 11:49:33AM +0000, Joseph S. Myers wrote:
> > > This sounds like something for which it should be easy to add a testcase
> > > to the testsuite.
> > >
> > > --
> > Here.
> >
> Which still shows that pattern is modified, now question is where.
After bit of debugging it was caused by different part of code. I
skipped this in previous attemp because flags &= ~(GLOB_NOCHECK looked
like unconditional statement.
[BZ #10246]
* posix/glob.c (glob): Return correct value when GLOB_NOCHECK
is specified.
* posix/tst-gnuglob.c (main): Add testcase.
diff --git a/posix/glob.c b/posix/glob.c
index 85237c2..4b639b4 100644
--- a/posix/glob.c
+++ b/posix/glob.c
@@ -1188,10 +1188,12 @@ glob (pattern, flags, errfunc, pglob)
}
if (dirname_modified)
flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC);
- status = glob_in_dir (filename, dirname, flags, errfunc, pglob,
- alloca_used);
+ status = glob_in_dir (filename, dirname, flags & ~GLOB_NOCHECK,
+ errfunc, pglob, alloca_used);
if (status != 0)
{
+ if (status == GLOB_NOMATCH && flags & GLOB_NOCHECK)
+ goto no_matches;
if (status == GLOB_NOMATCH && flags != orig_flags
&& pglob->gl_pathc + pglob->gl_offs == oldcount)
{
diff --git a/posix/tst-gnuglob.c b/posix/tst-gnuglob.c
index 6e42724..89bd223 100644
--- a/posix/tst-gnuglob.c
+++ b/posix/tst-gnuglob.c
@@ -392,6 +392,14 @@ main (void)
memset (&gl, '\0', sizeof (gl));
+ glob ("//foo", GLOB_NOCHECK, NULL, &gl);
+ printf ("results for glob (\"//foo\", 0)\n %s\n", gl.gl_pathv[0]);
+ if (strcmp(gl.gl_pathv[0],"//foo"))
+ {
+ printf ("failed\n");
+ result = 1;
+ }
+
gl.gl_closedir = my_closedir;
gl.gl_readdir = my_readdir;
gl.gl_opendir = my_opendir;