diff options
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/glob.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c index 692e81045..0341225cd 100644 --- a/openbsd-compat/glob.c +++ b/openbsd-compat/glob.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: glob.c,v 1.34 2010/10/08 21:48:42 nicm Exp $ */ | 1 | /* $OpenBSD: glob.c,v 1.35 2011/01/12 01:53:14 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 1989, 1993 | 3 | * Copyright (c) 1989, 1993 |
4 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
@@ -184,6 +184,11 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int), | |||
184 | pglob->gl_errfunc = errfunc; | 184 | pglob->gl_errfunc = errfunc; |
185 | pglob->gl_matchc = 0; | 185 | pglob->gl_matchc = 0; |
186 | 186 | ||
187 | if (pglob->gl_offs < 0 || pglob->gl_pathc < 0 || | ||
188 | pglob->gl_offs >= INT_MAX || pglob->gl_pathc >= INT_MAX || | ||
189 | pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1) | ||
190 | return GLOB_NOSPACE; | ||
191 | |||
187 | bufnext = patbuf; | 192 | bufnext = patbuf; |
188 | bufend = bufnext + MAXPATHLEN - 1; | 193 | bufend = bufnext + MAXPATHLEN - 1; |
189 | if (flags & GLOB_NOESCAPE) | 194 | if (flags & GLOB_NOESCAPE) |
@@ -752,10 +757,13 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, | |||
752 | struct stat **statv; | 757 | struct stat **statv; |
753 | 758 | ||
754 | newn = 2 + pglob->gl_pathc + pglob->gl_offs; | 759 | newn = 2 + pglob->gl_pathc + pglob->gl_offs; |
755 | if (SIZE_MAX / sizeof(*pathv) <= newn || | 760 | if (pglob->gl_offs >= INT_MAX || |
761 | pglob->gl_pathc >= INT_MAX || | ||
762 | newn >= INT_MAX || | ||
763 | SIZE_MAX / sizeof(*pathv) <= newn || | ||
756 | SIZE_MAX / sizeof(*statv) <= newn) { | 764 | SIZE_MAX / sizeof(*statv) <= newn) { |
757 | nospace: | 765 | nospace: |
758 | for (i = pglob->gl_offs; i < newn - 2; i++) { | 766 | for (i = pglob->gl_offs; i < (ssize_t)(newn - 2); i++) { |
759 | if (pglob->gl_pathv && pglob->gl_pathv[i]) | 767 | if (pglob->gl_pathv && pglob->gl_pathv[i]) |
760 | free(pglob->gl_pathv[i]); | 768 | free(pglob->gl_pathv[i]); |
761 | if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0 && | 769 | if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0 && |
@@ -870,7 +878,7 @@ match(Char *name, Char *pat, Char *patend) | |||
870 | ++pat; | 878 | ++pat; |
871 | while (((c = *pat++) & M_MASK) != M_END) { | 879 | while (((c = *pat++) & M_MASK) != M_END) { |
872 | if ((c & M_MASK) == M_CLASS) { | 880 | if ((c & M_MASK) == M_CLASS) { |
873 | int idx = *pat & M_MASK; | 881 | Char idx = *pat & M_MASK; |
874 | if (idx < NCCLASSES && | 882 | if (idx < NCCLASSES && |
875 | cclasses[idx].isctype(k)) | 883 | cclasses[idx].isctype(k)) |
876 | ok = 1; | 884 | ok = 1; |