From b68af624a9bf64fcf810a16a35749f4047ebe1ef Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Wed, 28 Mar 2001 21:05:26 +1000 Subject: [PATCH] - (djm) Sync openbsd-compat/glob.c --- ChangeLog | 3 +- configure.in | 26 +++++++------- openbsd-compat/glob.c | 81 ++++++++++++++++++++----------------------- 3 files changed, 52 insertions(+), 58 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6f7e8ae0a..1e138e87f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ fix from Philippe Levan - (djm) Rework krbIV tests to get us closer to building on Redhat. Still doesn't work because of conflicts between krbIV's and OpenSSL's des.h + - (djm) Sync openbsd-compat/glob.c 20010327 - Attempt sync with sshlogin.c w/ OpenBSD (mainly CVS ID) @@ -4734,4 +4735,4 @@ - Wrote replacements for strlcpy and mkdtemp - Released 1.0pre1 -$Id: ChangeLog,v 1.1024 2001/03/28 04:37:06 djm Exp $ +$Id: ChangeLog,v 1.1025 2001/03/28 11:05:26 djm Exp $ diff --git a/configure.in b/configure.in index 256443a93..792e629c5 100644 --- a/configure.in +++ b/configure.in @@ -1,4 +1,4 @@ -# $Id: configure.in,v 1.270 2001/03/28 04:37:06 djm Exp $ +# $Id: configure.in,v 1.271 2001/03/28 11:05:27 djm Exp $ AC_INIT(ssh.c) @@ -595,22 +595,22 @@ AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssldir, [ # Try to use $ssldir/lib if it exists, otherwise # $ssldir if test -d "$ssldir/lib" ; then - LDFLAGS="$saved_LDFLAGS -L$ssldir/lib" + LDFLAGS="-L$ssldir/lib $saved_LDFLAGS" if test ! -z "$need_dash_r" ; then - LDFLAGS="$LDFLAGS -R$ssldir/lib" + LDFLAGS="-R$ssldir/lib $LDFLAGS" fi else - LDFLAGS="$saved_LDFLAGS -L$ssldir" + LDFLAGS="-L$ssldir $saved_LDFLAGS" if test ! -z "$need_dash_r" ; then - LDFLAGS="$LDFLAGS -R$ssldir" + LDFLAGS="-R$ssldir $LDFLAGS" fi fi # Try to use $ssldir/include if it exists, otherwise # $ssldir if test -d "$ssldir/include" ; then - CPPFLAGS="$saved_CPPFLAGS -I$ssldir/include" + CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS" else - CPPFLAGS="$saved_CPPFLAGS -I$ssldir" + CPPFLAGS="-I$ssldir $saved_CPPFLAGS" fi fi @@ -657,22 +657,22 @@ if (test ! -z "$ac_cv_openssldir" && test "x$ac_cv_openssldir" != "x(system)") ; # Try to use $ssldir/lib if it exists, otherwise # $ssldir if test -d "$ssldir/lib" ; then - LDFLAGS="$saved_LDFLAGS -L$ssldir/lib" + LDFLAGS="-L$ssldir/lib $saved_LDFLAGS" if test ! -z "$need_dash_r" ; then - LDFLAGS="$LDFLAGS -R$ssldir/lib" + LDFLAGS="-R$ssldir/lib $LDFLAGS" fi else - LDFLAGS="$saved_LDFLAGS -L$ssldir" + LDFLAGS="-L$ssldir $saved_LDFLAGS" if test ! -z "$need_dash_r" ; then - LDFLAGS="$LDFLAGS -R$ssldir" + LDFLAGS="-R$ssldir $LDFLAGS" fi fi # Try to use $ssldir/include if it exists, otherwise # $ssldir if test -d "$ssldir/include" ; then - CPPFLAGS="$saved_CPPFLAGS -I$ssldir/include" + CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS" else - CPPFLAGS="$saved_CPPFLAGS -I$ssldir" + CPPFLAGS="-I$ssldir $saved_CPPFLAGS" fi fi fi diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c index 5ed286211..cca819de0 100644 --- a/openbsd-compat/glob.c +++ b/openbsd-compat/glob.c @@ -56,7 +56,7 @@ get_arg_max() #if 0 static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; #else -static char rcsid[] = "$OpenBSD: glob.c,v 1.10 2001/03/19 13:45:30 millert Exp $"; +static char rcsid[] = "$OpenBSD: glob.c,v 1.13 2001/03/28 08:00:00 deraadt Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -137,13 +137,10 @@ typedef char Char; static int compare __P((const void *, const void *)); -static void g_Ctoc __P((const Char *, char *)); +static int g_Ctoc __P((const Char *, char *, char *)); static int g_lstat __P((Char *, struct stat *, glob_t *)); static DIR *g_opendir __P((Char *, glob_t *)); static Char *g_strchr __P((Char *, int)); -#ifdef notdef -static Char *g_strcat __P((Char *, const Char *)); -#endif static int g_stat __P((Char *, struct stat *, glob_t *)); static int glob0 __P((const Char *, glob_t *)); static int glob1 __P((Char *, glob_t *, size_t *)); @@ -184,8 +181,8 @@ glob(pattern, flags, errfunc, pglob) bufnext = patbuf; bufend = bufnext + MAXPATHLEN; if (flags & GLOB_NOESCAPE) - while (bufnext < bufend && (c = *patnext++) != EOS) - *bufnext++ = c; + while (bufnext < bufend && (c = *patnext++) != EOS) + *bufnext++ = c; else { /* Protect the quoted characters. */ while (bufnext < bufend && (c = *patnext++) != EOS) @@ -279,7 +276,7 @@ static int globexp2(ptr, pattern, pglob, rv) return 0; } - for (i = 0, pl = pm = ptr; pm <= pe; pm++) + for (i = 0, pl = pm = ptr; pm <= pe; pm++) { switch (*pm) { case LBRACKET: /* Ignore everything between [] */ @@ -300,8 +297,8 @@ static int globexp2(ptr, pattern, pglob, rv) case RBRACE: if (i) { - i--; - break; + i--; + break; } /* FALLTHROUGH */ case COMMA: @@ -332,6 +329,7 @@ static int globexp2(ptr, pattern, pglob, rv) default: break; } + } *rv = 0; return 0; } @@ -464,7 +462,7 @@ glob0(pattern, pglob) * to avoid exponential behavior */ if (bufnext == patbuf || bufnext[-1] != M_ALL) - *bufnext++ = M_ALL; + *bufnext++ = M_ALL; break; default: *bufnext++ = CHAR(c); @@ -546,8 +544,8 @@ glob2(pathbuf, pathend, pattern, pglob, limitp) return(0); if (((pglob->gl_flags & GLOB_MARK) && - pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) - || (S_ISLNK(sb.st_mode) && + pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || + (S_ISLNK(sb.st_mode) && (g_stat(pathbuf, &sb, pglob) == 0) && S_ISDIR(sb.st_mode)))) { *pathend++ = SEP; @@ -571,7 +569,8 @@ glob2(pathbuf, pathend, pattern, pglob, limitp) pattern = p; while (*pattern == SEP) *pathend++ = *pattern++; - } else /* Need expansion, recurse. */ + } else + /* Need expansion, recurse. */ return(glob3(pathbuf, pathend, pattern, p, pglob, limitp)); } @@ -603,10 +602,11 @@ glob3(pathbuf, pathend, pattern, restpattern, pglob, limitp) if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { /* TODO: don't call for ENOENT or ENOTDIR? */ if (pglob->gl_errfunc) { - g_Ctoc(pathbuf, buf); + if (g_Ctoc(pathbuf, buf, buf+sizeof(buf))) + return(GLOB_ABORTED); if (pglob->gl_errfunc(buf, errno) || pglob->gl_flags & GLOB_ERR) - return (GLOB_ABORTED); + return(GLOB_ABORTED); } return(0); } @@ -695,7 +695,10 @@ globextend(path, pglob, limitp) len = (size_t)(p - path); *limitp += len; if ((copy = malloc(len)) != NULL) { - g_Ctoc(path, copy); + if (g_Ctoc(path, copy, copy+len+1)) { + free(copy); + return(GLOB_NOSPACE); + } pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; } pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; @@ -730,7 +733,8 @@ match(name, pat, patend) do if (match(name, pat, patend)) return(1); - while (*name++ != EOS); + while (*name++ != EOS) + ; return(0); case M_ONE: if (*name++ == EOS) @@ -788,8 +792,10 @@ g_opendir(str, pglob) if (!*str) strcpy(buf, "."); - else - g_Ctoc(str, buf); + else { + if (g_Ctoc(str, buf, buf+sizeof(buf))) + return(NULL); + } if (pglob->gl_flags & GLOB_ALTDIRFUNC) return((*pglob->gl_opendir)(buf)); @@ -805,7 +811,8 @@ g_lstat(fn, sb, pglob) { char buf[MAXPATHLEN]; - g_Ctoc(fn, buf); + if (g_Ctoc(fn, buf, buf+sizeof(buf))) + return(-1); if (pglob->gl_flags & GLOB_ALTDIRFUNC) return((*pglob->gl_lstat)(buf, sb)); return(lstat(buf, sb)); @@ -819,7 +826,8 @@ g_stat(fn, sb, pglob) { char buf[MAXPATHLEN]; - g_Ctoc(fn, buf); + if (g_Ctoc(fn, buf, buf+sizeof(buf))) + return(-1); if (pglob->gl_flags & GLOB_ALTDIRFUNC) return((*pglob->gl_stat)(buf, sb)); return(stat(buf, sb)); @@ -837,33 +845,18 @@ g_strchr(str, ch) return (NULL); } -#ifdef notdef -static Char * -g_strcat(dst, src) - Char *dst; - const Char* src; -{ - Char *sdst = dst; - - while (*dst++) - continue; - --dst; - while((*dst++ = *src++) != EOS) - continue; - - return (sdst); -} -#endif - -static void -g_Ctoc(str, buf) +static int +g_Ctoc(str, buf, ebuf) register const Char *str; - char *buf; + char *buf, *ebuf; { register char *dc; - for (dc = buf; (*dc++ = *str++) != EOS;) + for (dc = buf; dc < ebuf && (*dc++ = *str++) != EOS;) continue; + if (dc >= ebuf) + return (1); + return (0); } #ifdef DEBUG