diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-03-23 09:52:36 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-03-23 09:52:36 +0000 |
commit | 17a92b7327bb5ec42b6b4ccef9d88f8532e35c9a (patch) | |
tree | 15b5b1606a24b74c8584e1981410df0a7bc6d3a2 | |
parent | 7666f8be7817e144f1783d067807aecf37357517 (diff) |
Fix glob(3) to correctly return an error when its buffer space is
exhausted and GLOB_BRACE is given. globexp2() was ignoring errors
returned from lower levels.
While here, change globexp2() to return its return value normally rather
putting it in a int pointer then always returning 0.
ok otto
-rw-r--r-- | lib/libc/gen/glob.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c index 0c48932e4f0..11fa74ce023 100644 --- a/lib/libc/gen/glob.c +++ b/lib/libc/gen/glob.c @@ -1,4 +1,4 @@ -/* $OpenBSD: glob.c,v 1.29 2009/11/21 16:42:05 chl Exp $ */ +/* $OpenBSD: glob.c,v 1.30 2010/03/23 09:52:35 nicm Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -139,7 +139,7 @@ static int globextend(const Char *, glob_t *, size_t *); static const Char * globtilde(const Char *, Char *, size_t, glob_t *); static int globexp1(const Char *, glob_t *); -static int globexp2(const Char *, const Char *, glob_t *, int *); +static int globexp2(const Char *, const Char *, glob_t *); static int match(Char *, Char *, Char *); #ifdef DEBUG static void qprintf(const char *, Char *); @@ -204,9 +204,8 @@ globexp1(const Char *pattern, glob_t *pglob) if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) return glob0(pattern, pglob); - while ((ptr = (const Char *) g_strchr(ptr, LBRACE)) != NULL) - if (!globexp2(ptr, pattern, pglob, &rv)) - return rv; + if ((ptr = (const Char *) g_strchr(ptr, LBRACE)) != NULL) + return globexp2(ptr, pattern, pglob); return glob0(pattern, pglob); } @@ -218,9 +217,9 @@ globexp1(const Char *pattern, glob_t *pglob) * If it fails then it tries to glob the rest of the pattern and returns. */ static int -globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv) +globexp2(const Char *ptr, const Char *pattern, glob_t *pglob) { - int i; + int i, rv; Char *lm, *ls; const Char *pe, *pm, *pl; Char patbuf[MAXPATHLEN]; @@ -253,10 +252,8 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv) } /* Non matching braces; just glob the pattern */ - if (i != 0 || *pe == EOS) { - *rv = glob0(patbuf, pglob); - return 0; - } + if (i != 0 || *pe == EOS) + return glob0(patbuf, pglob); for (i = 0, pl = pm = ptr; pm <= pe; pm++) { switch (*pm) { @@ -302,7 +299,9 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv) #ifdef DEBUG qprintf("globexp2:", patbuf); #endif - *rv = globexp1(patbuf, pglob); + rv = globexp1(patbuf, pglob); + if (rv && rv != GLOB_NOMATCH) + return rv; /* move after the comma, to the next string */ pl = pm + 1; @@ -313,7 +312,6 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv) break; } } - *rv = 0; return 0; } |