diff mbox

expand: Fix glibc glob(3) support

Message ID 20180325080609.GA5452@gondor.apana.org.au (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show

Commit Message

Herbert Xu March 25, 2018, 8:06 a.m. UTC
It's been a while since we disabled glob(3) support by default.
It appears to be working now, however, we have to change our
code to remove a workaround that now actually prevents it from
working.

In particular, we no longer use GLOB_NOMAGIC or test GLOB_MAGCHAR.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Comments

Harald van Dijk March 25, 2018, 11:36 a.m. UTC | #1
On 3/25/18 10:06 AM, Herbert Xu wrote:
> It's been a while since we disabled glob(3) support by default.
> It appears to be working now, however, we have to change our
> code to remove a workaround that now actually prevents it from
> working.
> 
> In particular, we no longer use GLOB_NOMAGIC or test GLOB_MAGCHAR.

I thought that was an optimisation to avoid unnecessary file system 
access, to ensure that simple commands such as "echo ok" don't bother 
looking for files named "echo" and "ok" in the current directory.

It indeed doesn't work, but I took that to be a glibc bug.

Cheers,
Harald van Dijk
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Herbert Xu March 25, 2018, 4:27 p.m. UTC | #2
On Sun, Mar 25, 2018 at 01:36:54PM +0200, Harald van Dijk wrote:
> 
> I thought that was an optimisation to avoid unnecessary file system access,
> to ensure that simple commands such as "echo ok" don't bother looking for
> files named "echo" and "ok" in the current directory.
> 
> It indeed doesn't work, but I took that to be a glibc bug.

Good point.  It's been so long since I last discovered this :)

I tried making it work, and it looks like it should work with
the latest glibc as they have just fixed a critical issue that
would otherwise require nasty hacks to work around:

	https://sourceware.org/bugzilla/show_bug.cgi?id=866

So I'll give it some time to filter through before trying it again.

Thanks,
diff mbox

Patch

diff --git a/src/expand.c b/src/expand.c
index 705fef7..6d2a94a 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -1183,19 +1183,16 @@  expandmeta(str, flag)
 			goto nometa;
 		INTOFF;
 		p = preglob(str->text, RMESCAPE_ALLOC | RMESCAPE_HEAP);
-		i = glob(p, GLOB_NOMAGIC, 0, &pglob);
+		i = glob(p, 0, 0, &pglob);
 		if (p != str->text)
 			ckfree(p);
 		switch (i) {
 		case 0:
-			if (!(pglob.gl_flags & GLOB_MAGCHAR))
-				goto nometa2;
 			addglob(&pglob);
 			globfree(&pglob);
 			INTON;
 			break;
 		case GLOB_NOMATCH:
-nometa2:
 			globfree(&pglob);
 			INTON;
 nometa: