diff options
| author | christos <christos@NetBSD.org> | 2007-12-05 20:25:54 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2007-12-05 20:25:54 +0000 |
| commit | 14c8a5258015dc2f536dde2793099045edd024aa (patch) | |
| tree | d3a80b9eb73d8ce5b8d963661d09683ab4349445 | |
| parent | 21d75f870d9f15a187d6e8e766f60ad6cab77da2 (diff) | |
From Richard M Kreuter, add GLOB_PERIOD.
| -rw-r--r-- | include/glob.h | 3 | ||||
| -rw-r--r-- | lib/libc/gen/glob.3 | 6 | ||||
| -rw-r--r-- | lib/libc/gen/glob.c | 16 |
3 files changed, 17 insertions, 8 deletions
diff --git a/include/glob.h b/include/glob.h index a187224b4ab..218b5c03102 100644 --- a/include/glob.h +++ b/include/glob.h @@ -1,4 +1,4 @@ -/* $NetBSD: glob.h,v 1.21 2006/03/26 18:11:22 christos Exp $ */ +/* $NetBSD: glob.h,v 1.22 2007/12/05 20:25:54 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -90,6 +90,7 @@ typedef struct { #define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ #define GLOB_LIMIT 0x0400 /* Limit memory used by matches to ARG_MAX */ #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ +#define GLOB_PERIOD 0x1000 /* Allow metachars to match leading periods. */ #define GLOB_QUOTE 0 /* source compatibility */ #define GLOB_ABEND GLOB_ABORTED /* source compatibility */ diff --git a/lib/libc/gen/glob.3 b/lib/libc/gen/glob.3 index 364ebdcc9b8..57e3b33ca25 100644 --- a/lib/libc/gen/glob.3 +++ b/lib/libc/gen/glob.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: glob.3,v 1.30 2006/03/26 18:11:22 christos Exp $ +.\" $NetBSD: glob.3,v 1.31 2007/12/05 20:25:55 christos Exp $ .\" .\" Copyright (c) 1989, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -31,7 +31,7 @@ .\" .\" @(#)glob.3 8.3 (Berkeley) 4/16/94 .\" -.Dd March 22, 2006 +.Dd December 4, 2007 .Dt GLOB 3 .Os .Sh NAME @@ -259,6 +259,8 @@ This option should be set for programs that can be coerced to a denial of service attack via patterns that expand to a very large number of matches, such as a long string of .Li */../*/.. +.It Dv GLOB_PERIOD +Allow metacharacters to match a leading period in a filename. .El .Pp If, during the search, a directory is encountered that cannot be opened diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c index dcadb539765..0fe567ecc30 100644 --- a/lib/libc/gen/glob.c +++ b/lib/libc/gen/glob.c @@ -1,4 +1,4 @@ -/* $NetBSD: glob.c,v 1.18 2006/12/01 18:57:29 christos Exp $ */ +/* $NetBSD: glob.c,v 1.19 2007/12/05 20:25:56 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; #else -__RCSID("$NetBSD: glob.c,v 1.18 2006/12/01 18:57:29 christos Exp $"); +__RCSID("$NetBSD: glob.c,v 1.19 2007/12/05 20:25:56 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -59,6 +59,8 @@ __RCSID("$NetBSD: glob.c,v 1.18 2006/12/01 18:57:29 christos Exp $"); * expand ~user/foo to the /home/dir/of/user/foo * GLOB_BRACE: * expand {1,2}{a,b} to 1a 1b 2a 2b + * GLOB_PERIOD: + * allow metacharacters to match leading dots in filenames. * gl_matchc: * Number of matches in the current invocation of glob. */ @@ -695,9 +697,13 @@ glob3(Char *pathbuf, Char *pathend, Char *pathlim, Char *pattern, u_char *sc; Char *dc; - /* Initial DOT must be matched literally. */ - if (dp->d_name[0] == DOT && *pattern != DOT) - continue; + /* + * Initial DOT must be matched literally, unless we have + * GLOB_PERIOD set. + */ + if ((pglob->gl_flags & GLOB_PERIOD) == 0) + if (dp->d_name[0] == DOT && *pattern != DOT) + continue; /* * The resulting string contains EOS, so we can * use the pathlim character, if it is the nul |
