mailing list of musl libc
 help / color / mirror / code / Atom feed
* About GLOB_PERIOD behavior
@ 2017-01-12 13:31 Julien Ramseier
  0 siblings, 0 replies; only message in thread
From: Julien Ramseier @ 2017-01-12 13:31 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]

The GNU glob(3) GLOB_PERIOD extension seems to be broken in both glibc and musl.

glibc documents GLOB_PERIOD as "leading dots can be matched by metachars".
However in its current implementation, GLOB_PERIOD is only applied to the last
path component. Given the following file tree:
	usr/.dir/.file
	usr/bin/.file
glob("*/*/*", GLOB_PERIOD) will only match:
	usr/bin/.
	usr/bin/..
	usr/bin/.file

I don't know if this is intended...
It's also questionable whether GLOB_PERIOD should allow the special dot dirs
'.' and '..' to be matched.

In musl, GLOB_PERIOD affects each path component. But when '.' or '..' are
matched and the end of the pattern is not yet reached, it will start recursing
into these and produce totally wrong results. (Use the attached test script if
it's unclear).

I think we should either:
	- patch musl to behave like glibc
	- remove GLOB_PERIOD altogether

OpenBSD, FreeBSD and MacOSX don't implement GLOB_PERIOD.
NetBSD does but in the same broken way as musl, and also adds a GLOB_NO_DOTDIRS
extension to exclude '.' and '..'


[-- Attachment #2: t_glob.sh --]
[-- Type: application/octet-stream, Size: 458 bytes --]

#!/bin/sh

[ -n "$CC" ] || CC=gcc
"$CC" -std=c99 -x c - -o t_glob <<EOF
#include <stdio.h>
#include <glob.h>

int main(int argc, char *argv[])
{
	if (argc < 2) return 1;
	char *pattern = argv[1];
	glob_t g = {0};
	glob(pattern, GLOB_PERIOD, NULL, &g);
	for (size_t i = 0; i < g.gl_pathc; i++)
		printf("%s\n", g.gl_pathv[i]);
	return 0;
}
EOF

mkdir -p usr/.dir/
touch usr/.dir/.file
mkdir -p usr/bin/
touch usr/bin/cat
touch usr/bin/.file

./t_glob '*/*/*'

[-- Attachment #3: Type: text/plain, Size: 2 bytes --]




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-01-12 13:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-12 13:31 About GLOB_PERIOD behavior Julien Ramseier

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).