Lines Matching +full:dc +full:- +full:current +full:- +full:limit
36 * From: FreeBSD: head/lib/libc/gen/glob.c 317913 2017-05-07 19:52:56Z jilles
58 #include "gen-compat.h"
59 #include "glob-compat11.h"
64 * also CVE-2010-2632
86 #define RANGE L'-'
109 #define M_RNG META(L'-')
154 struct glob_limit limit = { 0, 0, 0, 0, 0 }; in freebsd11_glob() local
164 pglob->gl_pathc = 0; in freebsd11_glob()
165 pglob->gl_pathv = NULL; in freebsd11_glob()
167 pglob->gl_offs = 0; in freebsd11_glob()
170 limit.l_path_lim = pglob->gl_matchc; in freebsd11_glob()
171 if (limit.l_path_lim == 0) in freebsd11_glob()
172 limit.l_path_lim = GLOB_LIMIT_PATH; in freebsd11_glob()
174 pglob->gl_flags = flags & ~GLOB_MAGCHAR; in freebsd11_glob()
175 pglob->gl_errfunc = errfunc; in freebsd11_glob()
176 pglob->gl_matchc = 0; in freebsd11_glob()
179 bufend = bufnext + MAXPATHLEN - 1; in freebsd11_glob()
185 if (clen == (size_t)-1 || clen == (size_t)-2) in freebsd11_glob()
186 return (err_nomatch(pglob, &limit, pattern)); in freebsd11_glob()
207 if (clen == (size_t)-1 || clen == (size_t)-2) in freebsd11_glob()
208 return (err_nomatch(pglob, &limit, pattern)); in freebsd11_glob()
218 return (err_nomatch(pglob, &limit, pattern)); in freebsd11_glob()
222 return (globexp0(patbuf, pglob, &limit, pattern)); in freebsd11_glob()
224 return (glob0(patbuf, pglob, &limit, pattern)); in freebsd11_glob()
228 globexp0(const Char *pattern, glob11_t *pglob, struct glob_limit *limit, in globexp0() argument
235 if ((pglob->gl_flags & GLOB_LIMIT) && in globexp0()
236 limit->l_brace_cnt++ >= GLOB_LIMIT_BRACE) { in globexp0()
240 return (glob0(pattern, pglob, limit, origpat)); in globexp0()
243 oldpathc = pglob->gl_pathc; in globexp0()
245 if ((rv = globexp1(pattern, pglob, limit)) != 0) in globexp0()
248 return (globfinal(pglob, limit, oldpathc, origpat)); in globexp0()
257 globexp1(const Char *pattern, glob11_t *pglob, struct glob_limit *limit) in globexp1() argument
262 if ((pglob->gl_flags & GLOB_LIMIT) && in globexp1()
263 limit->l_brace_cnt++ >= GLOB_LIMIT_BRACE) { in globexp1()
267 return (globexp2(ptr, pattern, pglob, limit)); in globexp1()
270 return (glob0(pattern, pglob, limit, NULL)); in globexp1()
281 struct glob_limit *limit) in globexp2() argument
313 i--; in globexp2()
318 return (glob0(pattern, pglob, limit, NULL)); in globexp2()
341 i--; in globexp2()
349 /* Append the current string */ in globexp2()
359 /* Expand the current pattern */ in globexp2()
363 rv = globexp1(patbuf, pglob, limit); in globexp2()
392 wchar_t *wbufend, *dc; in globtilde() local
397 if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE)) in globtilde()
403 eb = &patbuf[patbuf_len - 1]; in globtilde()
424 h = pwd->pw_dir; in globtilde()
438 h = pwd->pw_dir; in globtilde()
442 dc = wbuf; in globtilde()
444 wbufend = wbuf + MAXPATHLEN - 1; in globtilde()
447 while (dc <= wbufend) { in globtilde()
449 if (clen == (size_t)-1 || clen == (size_t)-2) { in globtilde()
455 if ((*dc++ = wc) == EOS) { in globtilde()
464 dc = wbuf; in globtilde()
465 for (b = patbuf; b < eb && *dc != EOS; *b++ = *dc++ | M_PROTECT) in globtilde()
467 if (*dc != EOS) in globtilde()
495 glob0(const Char *pattern, glob11_t *pglob, struct glob_limit *limit, in glob0() argument
507 oldpathc = pglob->gl_pathc; in glob0()
521 --qpatnext; in glob0()
537 pglob->gl_flags |= GLOB_MAGCHAR; in glob0()
541 pglob->gl_flags |= GLOB_MAGCHAR; in glob0()
545 pglob->gl_flags |= GLOB_MAGCHAR; in glob0()
549 if (bufnext == patbuf || bufnext[-1] != M_ALL) in glob0()
562 if ((err = glob1(patbuf, pglob, limit)) != 0) in glob0()
566 return (globfinal(pglob, limit, oldpathc, origpat)); in glob0()
572 globfinal(glob11_t *pglob, struct glob_limit *limit, size_t oldpathc, in globfinal() argument
574 if (pglob->gl_pathc == oldpathc) in globfinal()
575 return (err_nomatch(pglob, limit, origpat)); in globfinal()
577 if (!(pglob->gl_flags & GLOB_NOSORT)) in globfinal()
578 qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, in globfinal()
579 pglob->gl_pathc - oldpathc, sizeof(char *), compare); in globfinal()
591 glob1(Char *pattern, glob11_t *pglob, struct glob_limit *limit) in glob1() argument
595 /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */ in glob1()
598 return (glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1, in glob1()
599 pattern, pglob, limit)); in glob1()
609 glob11_t *pglob, struct glob_limit *limit) in glob2() argument
625 if ((pglob->gl_flags & GLOB_LIMIT) && in glob2()
626 limit->l_stat_cnt++ >= GLOB_LIMIT_STAT) { in glob2()
630 if ((pglob->gl_flags & GLOB_MARK) && in glob2()
631 UNPROT(pathend[-1]) != SEP && in glob2()
643 ++pglob->gl_matchc; in glob2()
644 return (globextend(pathbuf, pglob, limit, NULL)); in glob2()
672 p, pglob, limit)); in glob2()
680 glob11_t *pglob, struct glob_limit *limit) in glob3() argument
685 char buf[MAXPATHLEN + MB_LEN_MAX - 1]; in glob3()
694 if (pglob->gl_errfunc != NULL && in glob3()
713 /* pglob->gl_readdir takes a void *, fix this manually */ in glob3()
714 if (pglob->gl_flags & GLOB_ALTDIRFUNC) in glob3()
716 (struct freebsd11_dirent *(*)(DIR *))pglob->gl_readdir; in glob3()
724 Char *dc; in glob3() local
729 if ((pglob->gl_flags & GLOB_LIMIT) && in glob3()
730 limit->l_readdir_cnt++ >= GLOB_LIMIT_READDIR) { in glob3()
737 if (dp->d_name[0] == '.' && UNPROT(*pattern) != DOT) { in glob3()
742 dc = pathend; in glob3()
743 sc = dp->d_name; in glob3()
745 while (dc <= pathend_last) { in glob3()
747 if (clen == (size_t)-1 || clen == (size_t)-2) { in glob3()
753 if ((*dc++ = wc) == EOS) { in glob3()
771 err = glob2(pathbuf, --dc, pathend_last, restpattern, in glob3()
772 pglob, limit); in glob3()
779 if (pglob->gl_flags & GLOB_ALTDIRFUNC) in glob3()
780 (*pglob->gl_closedir)(dirp); in glob3()
803 * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
813 globextend(const Char *path, glob11_t *pglob, struct glob_limit *limit, in globextend() argument
821 if ((pglob->gl_flags & GLOB_LIMIT) && in globextend()
822 pglob->gl_matchc > limit->l_path_lim) { in globextend()
827 newn = 2 + pglob->gl_pathc + pglob->gl_offs; in globextend()
829 pathv = reallocarray(pglob->gl_pathv, newn, sizeof(*pathv)); in globextend()
833 if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { in globextend()
834 /* first time around -- clear initial gl_offs items */ in globextend()
835 pathv += pglob->gl_offs; in globextend()
836 for (i = pglob->gl_offs + 1; --i > 0; ) in globextend()
837 *--pathv = NULL; in globextend()
839 pglob->gl_pathv = pathv; in globextend()
846 len = MB_CUR_MAX * (size_t)(p - path); /* XXX overallocation */ in globextend()
856 limit->l_string_cnt += strlen(copy) + 1; in globextend()
857 if ((pglob->gl_flags & GLOB_LIMIT) && in globextend()
858 limit->l_string_cnt >= GLOB_LIMIT_STRING) { in globextend()
863 pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; in globextend()
865 pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; in globextend()
878 (struct xlocale_collate*)__get_locale()->components[XLC_COLLATE]; in match()
893 nextp = pat - 1; in match()
908 if (table->__collate_load_error ? in match()
947 if (pglob->gl_pathv != NULL) { in freebsd11_globfree()
948 pp = pglob->gl_pathv + pglob->gl_offs; in freebsd11_globfree()
949 for (i = pglob->gl_pathc; i--; ++pp) in freebsd11_globfree()
952 free(pglob->gl_pathv); in freebsd11_globfree()
953 pglob->gl_pathv = NULL; in freebsd11_globfree()
960 char buf[MAXPATHLEN + MB_LEN_MAX - 1]; in g_opendir()
971 if (pglob->gl_flags & GLOB_ALTDIRFUNC) in g_opendir()
972 return ((*pglob->gl_opendir)(buf)); in g_opendir()
980 char buf[MAXPATHLEN + MB_LEN_MAX - 1]; in g_lstat()
984 return (-1); in g_lstat()
986 if (pglob->gl_flags & GLOB_ALTDIRFUNC) in g_lstat()
987 return((*pglob->gl_lstat)(buf, sb)); in g_lstat()
994 char buf[MAXPATHLEN + MB_LEN_MAX - 1]; in g_stat()
998 return (-1); in g_stat()
1000 if (pglob->gl_flags & GLOB_ALTDIRFUNC) in g_stat()
1001 return ((*pglob->gl_stat)(buf, sb)); in g_stat()
1025 if (clen == (size_t)-1) { in g_Ctoc()
1035 len -= clen; in g_Ctoc()
1041 err_nomatch(glob11_t *pglob, struct glob_limit *limit, const char *origpat) { in err_nomatch() argument
1048 if ((pglob->gl_flags & GLOB_NOCHECK) || in err_nomatch()
1049 ((pglob->gl_flags & GLOB_NOMAGIC) && in err_nomatch()
1050 !(pglob->gl_flags & GLOB_MAGCHAR))) in err_nomatch()
1051 return (globextend(NULL, pglob, limit, origpat)); in err_nomatch()
1057 if ((pglob->gl_errfunc != NULL && pglob->gl_errfunc(buf, err)) || in err_aborted()
1058 (pglob->gl_flags & GLOB_ERR)) in err_aborted()