diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2019-02-04 16:45:41 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2019-02-04 16:45:41 +0000 |
commit | 3e79e4169ef6258bd8428545b8028a4b478ca1fe (patch) | |
tree | 2140a038f1cbb60fc2ed0c5e6293f94674a589b8 /lib/libc/gen | |
parent | 66dd949ade2bf91e71a63b26f5d4651f4aa86178 (diff) |
Make gl_pathc, gl_matchc and gl_offs size_t in glob_t to match POSIX.
This requires a libc major version bump. OK deraadt@
Diffstat (limited to 'lib/libc/gen')
-rw-r--r-- | lib/libc/gen/glob.3 | 16 | ||||
-rw-r--r-- | lib/libc/gen/glob.c | 33 |
2 files changed, 24 insertions, 25 deletions
diff --git a/lib/libc/gen/glob.3 b/lib/libc/gen/glob.3 index 016324254b6..0d3aaed8835 100644 --- a/lib/libc/gen/glob.3 +++ b/lib/libc/gen/glob.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: glob.3,v 1.35 2017/07/06 15:42:04 schwarze Exp $ +.\" $OpenBSD: glob.3,v 1.36 2019/02/04 16:45:40 millert Exp $ .\" .\" Copyright (c) 1989, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 6 2017 $ +.Dd $Mdocdate: February 4 2019 $ .Dt GLOB 3 .Os .Sh NAME @@ -53,13 +53,13 @@ The include file defines the structure type .Li glob_t , which contains at least the following fields: -.Bd -literal -offset indent +.Bd -literal typedef struct { - int gl_pathc; /* count of total paths so far */ - int gl_matchc; /* count of paths matching pattern */ - int gl_offs; /* reserved at beginning of gl_pathv */ - int gl_flags; /* returned flags */ - char **gl_pathv; /* list of paths matching pattern */ + size_t gl_pathc; /* count of total paths so far */ + size_t gl_matchc; /* count of paths matching pattern */ + size_t gl_offs; /* reserved at beginning of gl_pathv */ + int gl_flags; /* returned flags */ + char **gl_pathv; /* list of paths matching pattern */ } glob_t; .Ed .Pp diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c index dafae849196..8b69031d54f 100644 --- a/lib/libc/gen/glob.c +++ b/lib/libc/gen/glob.c @@ -1,4 +1,4 @@ -/* $OpenBSD: glob.c,v 1.47 2017/05/08 14:53:27 millert Exp $ */ +/* $OpenBSD: glob.c,v 1.48 2019/02/04 16:45:40 millert Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -139,7 +139,7 @@ struct glob_path_stat { static int compare(const void *, const void *); static int compare_gps(const void *, const void *); -static int g_Ctoc(const Char *, char *, u_int); +static int g_Ctoc(const Char *, char *, size_t); static int g_lstat(Char *, struct stat *, glob_t *); static DIR *g_opendir(Char *, glob_t *); static Char *g_strchr(const Char *, int); @@ -187,9 +187,8 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int), if (strnlen(pattern, PATH_MAX) == PATH_MAX) return(GLOB_NOMATCH); - if (pglob->gl_offs < 0 || pglob->gl_pathc < 0 || - pglob->gl_offs >= INT_MAX || pglob->gl_pathc >= INT_MAX || - pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1) + if (pglob->gl_offs >= SSIZE_MAX || pglob->gl_pathc >= SSIZE_MAX || + pglob->gl_pathc >= SSIZE_MAX - pglob->gl_offs - 1) return GLOB_NOSPACE; bufnext = patbuf; @@ -462,7 +461,8 @@ static int glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) { const Char *qpatnext; - int c, err, oldpathc; + int c, err; + size_t oldpathc; Char *bufnext, patbuf[PATH_MAX]; qpatnext = globtilde(pattern, patbuf, PATH_MAX, pglob); @@ -556,9 +556,9 @@ glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) if ((pglob->gl_flags & GLOB_KEEPSTAT)) { /* Keep the paths and stat info synced during sort */ struct glob_path_stat *path_stat; - int i; - int n = pglob->gl_pathc - oldpathc; - int o = pglob->gl_offs + oldpathc; + size_t i; + size_t n = pglob->gl_pathc - oldpathc; + size_t o = pglob->gl_offs + oldpathc; if ((path_stat = calloc(n, sizeof(*path_stat))) == NULL) return GLOB_NOSPACE; @@ -787,20 +787,19 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, struct stat *sb) { char **pathv; - ssize_t i; - size_t newn, len; + size_t i, newn, len; char *copy = NULL; const Char *p; struct stat **statv; newn = 2 + pglob->gl_pathc + pglob->gl_offs; - if (pglob->gl_offs >= INT_MAX || - pglob->gl_pathc >= INT_MAX || - newn >= INT_MAX || + if (pglob->gl_offs >= SSIZE_MAX || + pglob->gl_pathc >= SSIZE_MAX || + newn >= SSIZE_MAX || SIZE_MAX / sizeof(*pathv) <= newn || SIZE_MAX / sizeof(*statv) <= newn) { nospace: - for (i = pglob->gl_offs; i < (ssize_t)(newn - 2); i++) { + for (i = pglob->gl_offs; i < newn - 2; i++) { if (pglob->gl_pathv && pglob->gl_pathv[i]) free(pglob->gl_pathv[i]); if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0 && @@ -961,7 +960,7 @@ fail: void globfree(glob_t *pglob) { - int i; + size_t i; char **pp; if (pglob->gl_pathv != NULL) { @@ -1033,7 +1032,7 @@ g_strchr(const Char *str, int ch) } static int -g_Ctoc(const Char *str, char *buf, u_int len) +g_Ctoc(const Char *str, char *buf, size_t len) { while (len--) { |