diff options
author | John Sonnenschein <johns@joyent.com> | 2011-10-03 21:04:40 +0000 |
---|---|---|
committer | John Sonnenschein <johns@joyent.com> | 2011-10-03 21:04:40 +0000 |
commit | 4171a80dc48c62297457d0820f26cac6516e068a (patch) | |
tree | 5e20c8b91e74482baeed81d9cda1af2f63207b82 /usr/src/cmd/ssh | |
parent | cb866ae1d95a57b3ac6bf38040e40ed0cd4fe835 (diff) | |
parent | ed22c7109fc5dd9e1b7a5d0333bdc7ad2718e2ab (diff) | |
download | illumos-joyent-4171a80dc48c62297457d0820f26cac6516e068a.tar.gz |
[OS-663] Post-6.5 Illumos sync
Merge https://github.com/illumos/illumos-gate
Conflicts:
exception_lists/packaging
usr/src/cmd/dtrace/test/cmd/scripts/dtest.pl
usr/src/cmd/dtrace/test/tst/common/usdt/tst.badguess.ksh
usr/src/cmd/dtrace/test/tst/common/usdt/tst.enabled2.ksh
usr/src/cmd/dtrace/test/tst/common/usdt/tst.guess32.ksh
usr/src/cmd/dtrace/test/tst/common/usdt/tst.guess64.ksh
usr/src/cmd/dtrace/test/tst/common/usdt/tst.include.ksh
usr/src/cmd/dtrace/test/tst/common/usdt/tst.nodtrace.ksh
usr/src/cmd/dtrace/test/tst/common/usdt/tst.noreap.ksh
usr/src/cmd/dtrace/test/tst/common/usdt/tst.noreapring.ksh
usr/src/cmd/dtrace/test/tst/common/usdt/tst.reap.ksh
usr/src/cmd/lp/Makefile
usr/src/cmd/lp/cmd/lpadmin/options.c
usr/src/cmd/lp/cmd/lpfilter.c
usr/src/cmd/lp/cmd/lpforms.c
usr/src/cmd/lp/cmd/lpusers.c
usr/src/cmd/lp/lib/lp/isterminfo.c
usr/src/cmd/lp/lib/lp/tidbit.c
usr/src/cmd/terminfo/att.ti
usr/src/cmd/zpool/zpool_main.c
usr/src/common/dis/i386/dis_tables.c
usr/src/lib/libdtrace/common/dt_options.c
usr/src/lib/libzfs/common/libzfs_dataset.c
usr/src/man/man1m/dladm.1m
usr/src/man/man1m/flowadm.1m
usr/src/man/man1m/zoneadm.1m
usr/src/man/man1m/zonecfg.1m
usr/src/pkg/manifests/print-lp-print-client-commands.mf
usr/src/pkg/manifests/print-lp.mf
usr/src/uts/common/fs/zfs/sys/zio.h
usr/src/uts/common/fs/zfs/zio.c
usr/src/uts/i86pc/ml/mach_offsets.in
usr/src/uts/intel/amd64/ml/mach_offsets.in
usr/src/uts/intel/sys/tss.h
Diffstat (limited to 'usr/src/cmd/ssh')
-rw-r--r-- | usr/src/cmd/ssh/libopenbsd-compat/common/glob.c | 105 | ||||
-rw-r--r-- | usr/src/cmd/ssh/sftp/sftp-glob.c | 4 | ||||
-rw-r--r-- | usr/src/cmd/ssh/sftp/sftp.c | 2 |
3 files changed, 62 insertions, 49 deletions
diff --git a/usr/src/cmd/ssh/libopenbsd-compat/common/glob.c b/usr/src/cmd/ssh/libopenbsd-compat/common/glob.c index 87727fd96e..2688cccaee 100644 --- a/usr/src/cmd/ssh/libopenbsd-compat/common/glob.c +++ b/usr/src/cmd/ssh/libopenbsd-compat/common/glob.c @@ -37,18 +37,6 @@ #include "includes.h" #include <ctype.h> -static long -get_arg_max(void) -{ -#ifdef ARG_MAX - return(ARG_MAX); -#elif defined(HAVE_SYSCONF) && defined(_SC_ARG_MAX) - return(sysconf(_SC_ARG_MAX)); -#else - return(256); /* XXX: arbitrary */ -#endif -} - #if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \ !defined(GLOB_HAS_GL_MATCHC) @@ -137,13 +125,21 @@ typedef char Char; #define ismeta(c) (((c)&M_QUOTE) != 0) +#define GLOB_LIMIT_MALLOC 65536 +#define GLOB_LIMIT_STAT 128 +#define GLOB_LIMIT_READDIR 16384 + +#define GLOB_INDEX_MALLOC 0 +#define GLOB_INDEX_STAT 1 +#define GLOB_INDEX_READDIR 2 + static int compare(const void *, const void *); static int g_Ctoc(const Char *, char *, u_int); static int g_lstat(Char *, struct stat *, glob_t *); static DIR *g_opendir(Char *, glob_t *); static Char *g_strchr(Char *, int); static int g_stat(Char *, struct stat *, glob_t *); -static int glob0(const Char *, glob_t *); +static int glob0(const Char *, glob_t *, size_t *); static int glob1(Char *, Char *, glob_t *, size_t *); static int glob2(Char *, Char *, Char *, Char *, Char *, Char *, glob_t *, size_t *); @@ -152,8 +148,9 @@ static int glob3(Char *, Char *, Char *, Char *, Char *, Char *, 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 globexp1(const Char *, glob_t *, size_t *); +static int globexp2(const Char *, const Char *, glob_t *, int *, + size_t *); static int match(Char *, Char *, Char *); #ifdef DEBUG static void qprintf(const char *, Char *); @@ -168,6 +165,8 @@ glob(pattern, flags, errfunc, pglob) const u_char *patnext; int c; Char *bufnext, *bufend, patbuf[MAXPATHLEN]; + /* 0 = malloc(), 1 = stat(), 2 = readdir() */ + static size_t limit[] = { 0, 0, 0 }; patnext = (u_char *) pattern; if (!(flags & GLOB_APPEND)) { @@ -200,9 +199,9 @@ glob(pattern, flags, errfunc, pglob) *bufnext = EOS; if (flags & GLOB_BRACE) - return globexp1(patbuf, pglob); + return globexp1(patbuf, pglob, limit); else - return glob0(patbuf, pglob); + return glob0(patbuf, pglob, limit); } /* @@ -211,22 +210,23 @@ glob(pattern, flags, errfunc, pglob) * characters */ static int -globexp1(pattern, pglob) +globexp1(pattern, pglob, limit) const Char *pattern; glob_t *pglob; + size_t *limit; { const Char* ptr = pattern; int rv; /* Protect a single {}, for find(1), like csh */ if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) - return glob0(pattern, pglob); + return glob0(pattern, pglob, limit); while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL) - if (!globexp2(ptr, pattern, pglob, &rv)) + if (!globexp2(ptr, pattern, pglob, &rv, limit)) return rv; - return glob0(pattern, pglob); + return glob0(pattern, pglob, limit); } @@ -236,10 +236,11 @@ globexp1(pattern, pglob) * If it fails then it tries to glob the rest of the pattern and returns. */ static int -globexp2(ptr, pattern, pglob, rv) +globexp2(ptr, pattern, pglob, rv, limit) const Char *ptr, *pattern; glob_t *pglob; int *rv; + size_t *limit; { int i; Char *lm, *ls; @@ -275,7 +276,7 @@ globexp2(ptr, pattern, pglob, rv) /* Non matching braces; just glob the pattern */ if (i != 0 || *pe == EOS) { - *rv = glob0(patbuf, pglob); + *rv = glob0(patbuf, pglob, limit); return 0; } @@ -323,7 +324,7 @@ globexp2(ptr, pattern, pglob, rv) #ifdef DEBUG qprintf("globexp2:", patbuf); #endif - *rv = globexp1(patbuf, pglob); + *rv = globexp1(patbuf, pglob, limit); /* move after the comma, to the next string */ pl = pm + 1; @@ -416,14 +417,14 @@ globtilde(pattern, patbuf, patbuf_len, pglob) * to find no matches. */ static int -glob0(pattern, pglob) +glob0(pattern, pglob, limit) const Char *pattern; glob_t *pglob; + size_t *limit; { const Char *qpatnext; int c, err, oldpathc; Char *bufnext, patbuf[MAXPATHLEN]; - size_t limit = 0; qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob); oldpathc = pglob->gl_pathc; @@ -481,7 +482,7 @@ glob0(pattern, pglob) qprintf("glob0:", patbuf); #endif - if ((err = glob1(patbuf, patbuf+MAXPATHLEN-1, pglob, &limit)) != 0) + if ((err = glob1(patbuf, patbuf+MAXPATHLEN-1, pglob, limit)) != 0) return(err); /* @@ -494,7 +495,7 @@ glob0(pattern, pglob) if ((pglob->gl_flags & GLOB_NOCHECK) || ((pglob->gl_flags & GLOB_NOMAGIC) && !(pglob->gl_flags & GLOB_MAGCHAR))) - return(globextend(pattern, pglob, &limit)); + return(globextend(pattern, pglob, limit)); else return(GLOB_NOMATCH); } @@ -512,10 +513,10 @@ compare(p, q) } static int -glob1(pattern, pattern_last, pglob, limitp) +glob1(pattern, pattern_last, pglob, limit) Char *pattern, *pattern_last; glob_t *pglob; - size_t *limitp; + size_t *limit; { Char pathbuf[MAXPATHLEN]; @@ -524,7 +525,7 @@ glob1(pattern, pattern_last, pglob, limitp) return(0); return(glob2(pathbuf, pathbuf+MAXPATHLEN-1, pathbuf, pathbuf+MAXPATHLEN-1, - pattern, pattern_last, pglob, limitp)); + pattern, pattern_last, pglob, limit)); } /* @@ -534,11 +535,11 @@ glob1(pattern, pattern_last, pglob, limitp) */ static int glob2(pathbuf, pathbuf_last, pathend, pathend_last, pattern, - pattern_last, pglob, limitp) + pattern_last, pglob, limit) Char *pathbuf, *pathbuf_last, *pathend, *pathend_last; Char *pattern, *pattern_last; glob_t *pglob; - size_t *limitp; + size_t *limit; { struct stat sb; Char *p, *q; @@ -554,6 +555,14 @@ glob2(pathbuf, pathbuf_last, pathend, pathend_last, pattern, if (g_lstat(pathbuf, &sb, pglob)) return(0); + if ((pglob->gl_flags & GLOB_LIMIT) && + limit[GLOB_INDEX_STAT]++ >= GLOB_LIMIT_STAT) { + errno = 0; + *pathend++ = SEP; + *pathend = EOS; + return GLOB_NOSPACE; + } + if (((pglob->gl_flags & GLOB_MARK) && pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || (S_ISLNK(sb.st_mode) && @@ -565,7 +574,7 @@ glob2(pathbuf, pathbuf_last, pathend, pathend_last, pattern, *pathend = EOS; } ++pglob->gl_matchc; - return(globextend(pathbuf, pglob, limitp)); + return(globextend(pathbuf, pglob, limit)); } /* Find end of next segment, copy tentatively to pathend. */ @@ -591,18 +600,18 @@ glob2(pathbuf, pathbuf_last, pathend, pathend_last, pattern, /* Need expansion, recurse. */ return(glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, - p, pattern_last, pglob, limitp)); + p, pattern_last, pglob, limit)); } /* NOTREACHED */ } static int glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, - restpattern, restpattern_last, pglob, limitp) + restpattern, restpattern_last, pglob, limit) Char *pathbuf, *pathbuf_last, *pathend, *pathend_last; Char *pattern, *pattern_last, *restpattern, *restpattern_last; glob_t *pglob; - size_t *limitp; + size_t *limit; { register struct dirent *dp; DIR *dirp; @@ -645,6 +654,14 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, register u_char *sc; register Char *dc; + if ((pglob->gl_flags & GLOB_LIMIT) && + limit[GLOB_INDEX_READDIR]++ >= GLOB_LIMIT_READDIR) { + errno = 0; + *pathend++ = SEP; + *pathend = EOS; + return GLOB_NOSPACE; + } + /* Initial DOT must be matched literally. */ if (dp->d_name[0] == DOT && *pattern != DOT) continue; @@ -663,7 +680,7 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, continue; } err = glob2(pathbuf, pathbuf_last, --dc, pathend_last, - restpattern, restpattern_last, pglob, limitp); + restpattern, restpattern_last, pglob, limit); if (err) break; } @@ -691,10 +708,10 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, * gl_pathv points to (gl_offs + gl_pathc + 1) items. */ static int -globextend(path, pglob, limitp) +globextend(path, pglob, limit) const Char *path; glob_t *pglob; - size_t *limitp; + size_t *limit; { register char **pathv; register int i; @@ -724,7 +741,7 @@ globextend(path, pglob, limitp) for (p = path; *p++;) ; len = (size_t)(p - path); - *limitp += len; + limit[GLOB_INDEX_MALLOC] += len; if ((copy = malloc(len)) != NULL) { if (g_Ctoc(path, copy, len)) { free(copy); @@ -733,11 +750,10 @@ globextend(path, pglob, limitp) pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; } pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; - if ((pglob->gl_flags & GLOB_LIMIT) && - newsize + *limitp >= (u_int) get_arg_max()) { + (newsize + limit[GLOB_INDEX_MALLOC]) >= GLOB_LIMIT_MALLOC) { errno = 0; - return(GLOB_NOSPACE); + return GLOB_NOSPACE; } return(copy == NULL ? GLOB_NOSPACE : 0); @@ -915,4 +931,3 @@ qprintf(str, s) !defined(GLOB_HAS_GL_MATCHC) */ -#pragma ident "%Z%%M% %I% %E% SMI" diff --git a/usr/src/cmd/ssh/sftp/sftp-glob.c b/usr/src/cmd/ssh/sftp/sftp-glob.c index 856b3a2635..626e80922a 100644 --- a/usr/src/cmd/ssh/sftp/sftp-glob.c +++ b/usr/src/cmd/ssh/sftp/sftp-glob.c @@ -16,8 +16,6 @@ /* $OpenBSD: sftp-glob.c,v 1.22 2006/08/03 03:34:42 deraadt Exp $ */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include "includes.h" #include <sys/types.h> @@ -151,5 +149,5 @@ remote_glob(struct sftp_conn *conn, const char *pattern, int flags, memset(&cur, 0, sizeof(cur)); cur.conn = conn; - return(glob(pattern, flags | GLOB_ALTDIRFUNC, errfunc, pglob)); + return(glob(pattern, flags|GLOB_LIMIT|GLOB_ALTDIRFUNC, errfunc, pglob)); } diff --git a/usr/src/cmd/ssh/sftp/sftp.c b/usr/src/cmd/ssh/sftp/sftp.c index 9b5caac074..10b971f02c 100644 --- a/usr/src/cmd/ssh/sftp/sftp.c +++ b/usr/src/cmd/ssh/sftp/sftp.c @@ -617,7 +617,7 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag) memset(&g, 0, sizeof(g)); debug3("Looking up %s", src); - if (glob(src, 0, NULL, &g)) { + if (glob(src, GLOB_LIMIT, NULL, &g)) { error("File \"%s\" not found.", src); err = -1; goto out; |