diff options
-rw-r--r-- | kerberosV/src/lib/roken/daemon.c | 6 | ||||
-rw-r--r-- | kerberosV/src/lib/roken/fnmatch.c | 6 | ||||
-rw-r--r-- | kerberosV/src/lib/roken/fnmatch.hin | 6 | ||||
-rw-r--r-- | kerberosV/src/lib/roken/getcap.c | 6 | ||||
-rw-r--r-- | kerberosV/src/lib/roken/getopt.c | 6 | ||||
-rw-r--r-- | kerberosV/src/lib/roken/getusershell.c | 6 | ||||
-rw-r--r-- | kerberosV/src/lib/roken/glob.c | 71 | ||||
-rw-r--r-- | kerberosV/src/lib/roken/glob.hin | 7 | ||||
-rw-r--r-- | kerberosV/src/lib/roken/iruserok.c | 6 | ||||
-rw-r--r-- | kerberosV/src/lib/roken/unvis.c | 6 | ||||
-rw-r--r-- | kerberosV/src/lib/roken/vis.c | 140 | ||||
-rw-r--r-- | kerberosV/src/lib/roken/vis.hin | 6 |
12 files changed, 123 insertions, 149 deletions
diff --git a/kerberosV/src/lib/roken/daemon.c b/kerberosV/src/lib/roken/daemon.c index da80430bace..072e8d29156 100644 --- a/kerberosV/src/lib/roken/daemon.c +++ b/kerberosV/src/lib/roken/daemon.c @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/kerberosV/src/lib/roken/fnmatch.c b/kerberosV/src/lib/roken/fnmatch.c index dc01d6ea61b..e8bb44c876f 100644 --- a/kerberosV/src/lib/roken/fnmatch.c +++ b/kerberosV/src/lib/roken/fnmatch.c @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/kerberosV/src/lib/roken/fnmatch.hin b/kerberosV/src/lib/roken/fnmatch.hin index 95c91d600b6..41df392c23b 100644 --- a/kerberosV/src/lib/roken/fnmatch.hin +++ b/kerberosV/src/lib/roken/fnmatch.hin @@ -12,11 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/kerberosV/src/lib/roken/getcap.c b/kerberosV/src/lib/roken/getcap.c index 90e43d9c6da..04989a76933 100644 --- a/kerberosV/src/lib/roken/getcap.c +++ b/kerberosV/src/lib/roken/getcap.c @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/kerberosV/src/lib/roken/getopt.c b/kerberosV/src/lib/roken/getopt.c index 45fc3502345..d935c655506 100644 --- a/kerberosV/src/lib/roken/getopt.c +++ b/kerberosV/src/lib/roken/getopt.c @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/kerberosV/src/lib/roken/getusershell.c b/kerberosV/src/lib/roken/getusershell.c index f7dc4b2a14c..bf878776dd5 100644 --- a/kerberosV/src/lib/roken/getusershell.c +++ b/kerberosV/src/lib/roken/getusershell.c @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/kerberosV/src/lib/roken/glob.c b/kerberosV/src/lib/roken/glob.c index 66e8ec6db8c..55767ce7846 100644 --- a/kerberosV/src/lib/roken/glob.c +++ b/kerberosV/src/lib/roken/glob.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -87,10 +83,17 @@ #ifdef HAVE_UNISTD_H #include <unistd.h> #endif +#ifdef HAVE_LIMITS_H +#include <limits.h> +#endif #include "glob.h" #include "roken.h" +#ifndef ARG_MAX +#define ARG_MAX _POSIX_ARG_MAX +#endif + #define CHAR_DOLLAR '$' #define CHAR_DOT '.' #define CHAR_EOS '\0' @@ -145,16 +148,16 @@ static int compare (const void *, const void *); static void g_Ctoc (const Char *, char *); static int g_lstat (Char *, struct stat *, glob_t *); static DIR *g_opendir (Char *, glob_t *); -static Char *g_strchr (Char *, int); +static Char *g_strchr (const Char *, int); #ifdef notdef static Char *g_strcat (Char *, const Char *); #endif static int g_stat (Char *, struct stat *, glob_t *); static int glob0 (const Char *, glob_t *); -static int glob1 (Char *, glob_t *); -static int glob2 (Char *, Char *, Char *, glob_t *); -static int glob3 (Char *, Char *, Char *, Char *, glob_t *); -static int globextend (const Char *, glob_t *); +static int glob1 (Char *, glob_t *, size_t *); +static int glob2 (Char *, Char *, Char *, glob_t *, size_t *); +static int glob3 (Char *, Char *, Char *, Char *, glob_t *, size_t *); +static int globextend (const Char *, glob_t *, size_t *); static const Char * globtilde (const Char *, Char *, glob_t *); static int globexp1 (const Char *, glob_t *); static int globexp2 (const Char *, const Char *, glob_t *, int *); @@ -173,7 +176,7 @@ glob(const char *pattern, int c; Char *bufnext, *bufend, patbuf[MaxPathLen+1]; - patnext = (u_char *) pattern; + patnext = (const u_char *) pattern; if (!(flags & GLOB_APPEND)) { pglob->gl_pathc = 0; pglob->gl_pathv = NULL; @@ -224,7 +227,7 @@ static int globexp1(const Char *pattern, glob_t *pglob) if (pattern[0] == CHAR_LBRACE && pattern[1] == CHAR_RBRACE && pattern[2] == CHAR_EOS) return glob0(pattern, pglob); - while ((ptr = (const Char *) g_strchr((Char *) ptr, CHAR_LBRACE)) != NULL) + while ((ptr = (const Char *) g_strchr(ptr, CHAR_LBRACE)) != NULL) if (!globexp2(ptr, pattern, pglob, &rv)) return rv; @@ -405,6 +408,7 @@ glob0(const Char *pattern, glob_t *pglob) const Char *qpatnext; int c, err, oldpathc; Char *bufnext, patbuf[MaxPathLen+1]; + size_t limit = 0; qpatnext = globtilde(pattern, patbuf, pglob); oldpathc = pglob->gl_pathc; @@ -418,7 +422,7 @@ glob0(const Char *pattern, glob_t *pglob) if (c == CHAR_NOT) ++qpatnext; if (*qpatnext == CHAR_EOS || - g_strchr((Char *) qpatnext+1, CHAR_RBRACKET) == NULL) { + g_strchr(qpatnext+1, CHAR_RBRACKET) == NULL) { *bufnext++ = CHAR_LBRACKET; if (c == CHAR_NOT) --qpatnext; @@ -462,7 +466,7 @@ glob0(const Char *pattern, glob_t *pglob) qprintf("glob0:", patbuf); #endif - if ((err = glob1(patbuf, pglob)) != 0) + if ((err = glob1(patbuf, pglob, &limit)) != 0) return(err); /* @@ -475,7 +479,7 @@ glob0(const Char *pattern, glob_t *pglob) ((pglob->gl_flags & GLOB_NOCHECK) || ((pglob->gl_flags & GLOB_NOMAGIC) && !(pglob->gl_flags & GLOB_MAGCHAR)))) - return(globextend(pattern, pglob)); + return(globextend(pattern, pglob, &limit)); else if (!(pglob->gl_flags & GLOB_NOSORT)) qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, pglob->gl_pathc - oldpathc, sizeof(char *), compare); @@ -489,14 +493,14 @@ compare(const void *p, const void *q) } static int -glob1(Char *pattern, glob_t *pglob) +glob1(Char *pattern, glob_t *pglob, size_t *limit) { Char pathbuf[MaxPathLen+1]; /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */ if (*pattern == CHAR_EOS) return(0); - return(glob2(pathbuf, pathbuf, pattern, pglob)); + return(glob2(pathbuf, pathbuf, pattern, pglob, limit)); } /* @@ -514,7 +518,8 @@ glob1(Char *pattern, glob_t *pglob) #endif static int -glob2(Char *pathbuf, Char *pathend, Char *pattern, glob_t *pglob) +glob2(Char *pathbuf, Char *pathend, Char *pattern, glob_t *pglob, + size_t *limit) { struct stat sb; Char *p, *q; @@ -539,7 +544,7 @@ glob2(Char *pathbuf, Char *pathend, Char *pattern, glob_t *pglob) *pathend = CHAR_EOS; } ++pglob->gl_matchc; - return(globextend(pathbuf, pglob)); + return(globextend(pathbuf, pglob, limit)); } /* Find end of next segment, copy tentatively to pathend. */ @@ -557,14 +562,15 @@ glob2(Char *pathbuf, Char *pathend, Char *pattern, glob_t *pglob) while (*pattern == CHAR_SEP) *pathend++ = *pattern++; } else /* Need expansion, recurse. */ - return(glob3(pathbuf, pathend, pattern, p, pglob)); + return(glob3(pathbuf, pathend, pattern, p, pglob, + limit)); } - /* CHAR_NOTREACHED */ + /* NOTREACHED */ } static int glob3(Char *pathbuf, Char *pathend, Char *pattern, Char *restpattern, - glob_t *pglob) + glob_t *pglob, size_t *limit) { struct dirent *dp; DIR *dirp; @@ -614,7 +620,7 @@ glob3(Char *pathbuf, Char *pathend, Char *pattern, Char *restpattern, *pathend = CHAR_EOS; continue; } - err = glob2(pathbuf, --dc, restpattern, pglob); + err = glob2(pathbuf, --dc, restpattern, pglob, limit); if (err) break; } @@ -642,11 +648,11 @@ glob3(Char *pathbuf, Char *pathend, Char *pattern, Char *restpattern, * gl_pathv points to (gl_offs + gl_pathc + 1) items. */ static int -globextend(const Char *path, glob_t *pglob) +globextend(const Char *path, glob_t *pglob, size_t *limit) { char **pathv; int i; - u_int newsize; + size_t newsize, len; char *copy; const Char *p; @@ -667,11 +673,19 @@ globextend(const Char *path, glob_t *pglob) for (p = path; *p++;) continue; - if ((copy = malloc(p - path)) != NULL) { + len = (size_t)(p - path); + *limit += len; + if ((copy = malloc(len)) != NULL) { g_Ctoc(path, copy); pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; } pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; + + if ((pglob->gl_flags & GLOB_LIMIT) && (newsize + *limit) >= ARG_MAX) { + errno = 0; + return(GLOB_NOSPACE); + } + return(copy == NULL ? GLOB_NOSPACE : 0); } @@ -739,6 +753,7 @@ globfree(glob_t *pglob) if (*pp) free(*pp); free(pglob->gl_pathv); + pglob->gl_pathv = NULL; } } @@ -781,11 +796,11 @@ g_stat(Char *fn, struct stat *sb, glob_t *pglob) } static Char * -g_strchr(Char *str, int ch) +g_strchr(const Char *str, int ch) { do { if (*str == ch) - return (str); + return (Char *)str; } while (*str++); return (NULL); } diff --git a/kerberosV/src/lib/roken/glob.hin b/kerberosV/src/lib/roken/glob.hin index bece48a89cd..660d1edca31 100644 --- a/kerberosV/src/lib/roken/glob.hin +++ b/kerberosV/src/lib/roken/glob.hin @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -74,6 +70,7 @@ typedef struct { #define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ #define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ +#define GLOB_LIMIT 0x1000 /* Limit memory used by matches to ARG_MAX */ #define GLOB_NOSPACE (-1) /* Malloc call failed. */ #define GLOB_ABEND (-2) /* Unignored error. */ diff --git a/kerberosV/src/lib/roken/iruserok.c b/kerberosV/src/lib/roken/iruserok.c index faa6bcc7653..ed6046d3864 100644 --- a/kerberosV/src/lib/roken/iruserok.c +++ b/kerberosV/src/lib/roken/iruserok.c @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/kerberosV/src/lib/roken/unvis.c b/kerberosV/src/lib/roken/unvis.c index a7dc0de5261..fc3eaf0b1fb 100644 --- a/kerberosV/src/lib/roken/unvis.c +++ b/kerberosV/src/lib/roken/unvis.c @@ -12,11 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/kerberosV/src/lib/roken/vis.c b/kerberosV/src/lib/roken/vis.c index bfd423de2f6..d2cb1783f58 100644 --- a/kerberosV/src/lib/roken/vis.c +++ b/kerberosV/src/lib/roken/vis.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -38,7 +34,7 @@ #if 1 #ifdef HAVE_CONFIG_H #include <config.h> -RCSID("$KTH: vis.c,v 1.3 2000/12/10 23:10:48 assar Exp $"); +RCSID("$KTH: vis.c,v 1.5 2001/09/03 05:37:23 assar Exp $"); #endif #include <roken.h> #ifndef _DIAGASSERT @@ -107,71 +103,73 @@ do { \ * extra: Pointer to the list of extra characters to be * backslash-protected. */ -#define SVIS(dst, c, flag, nextc, extra) \ -do { \ - int isextra, isc; \ - isextra = strchr(extra, c) != NULL; \ - if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) || \ - ((flag & VIS_SAFE) && issafe(c)))) { \ - *dst++ = c; \ - break; \ - } \ - isc = 0; \ - if (flag & VIS_CSTYLE) { \ - switch (c) { \ - case '\n': \ - isc = 1; *dst++ = '\\'; *dst++ = 'n'; \ - break; \ - case '\r': \ - isc = 1; *dst++ = '\\'; *dst++ = 'r'; \ - break; \ - case '\b': \ - isc = 1; *dst++ = '\\'; *dst++ = 'b'; \ - break; \ - case BELL: \ - isc = 1; *dst++ = '\\'; *dst++ = 'a'; \ - break; \ - case '\v': \ - isc = 1; *dst++ = '\\'; *dst++ = 'v'; \ - break; \ - case '\t': \ - isc = 1; *dst++ = '\\'; *dst++ = 't'; \ - break; \ - case '\f': \ - isc = 1; *dst++ = '\\'; *dst++ = 'f'; \ - break; \ - case ' ': \ - isc = 1; *dst++ = '\\'; *dst++ = 's'; \ - break; \ - case '\0': \ - isc = 1; *dst++ = '\\'; *dst++ = '0'; \ - if (isoctal(nextc)) { \ - *dst++ = '0'; \ - *dst++ = '0'; \ - } \ - } \ - } \ - if (isc) break; \ - if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) { \ - *dst++ = '\\'; \ - *dst++ = (u_char)(((unsigned)(u_char)c >> 6) & 03) + '0'; \ - *dst++ = (u_char)(((unsigned)(u_char)c >> 3) & 07) + '0'; \ - *dst++ = (c & 07) + '0'; \ - } else { \ - if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\'; \ - if (c & 0200) { \ - c &= 0177; *dst++ = 'M'; \ - } \ - if (iscntrl(c)) { \ - *dst++ = '^'; \ - if (c == 0177) \ - *dst++ = '?'; \ - else \ - *dst++ = c + '@'; \ - } else { \ - *dst++ = '-'; *dst++ = c; \ - } \ - } \ +#define SVIS(dst, c, flag, nextc, extra) \ +do { \ + int isextra, isc; \ + isextra = strchr(extra, c) != NULL; \ + if (!isextra && \ + isascii((unsigned char)c) && \ + (isgraph((unsigned char)c) || iswhite(c) || \ + ((flag & VIS_SAFE) && issafe(c)))) { \ + *dst++ = c; \ + break; \ + } \ + isc = 0; \ + if (flag & VIS_CSTYLE) { \ + switch (c) { \ + case '\n': \ + isc = 1; *dst++ = '\\'; *dst++ = 'n'; \ + break; \ + case '\r': \ + isc = 1; *dst++ = '\\'; *dst++ = 'r'; \ + break; \ + case '\b': \ + isc = 1; *dst++ = '\\'; *dst++ = 'b'; \ + break; \ + case BELL: \ + isc = 1; *dst++ = '\\'; *dst++ = 'a'; \ + break; \ + case '\v': \ + isc = 1; *dst++ = '\\'; *dst++ = 'v'; \ + break; \ + case '\t': \ + isc = 1; *dst++ = '\\'; *dst++ = 't'; \ + break; \ + case '\f': \ + isc = 1; *dst++ = '\\'; *dst++ = 'f'; \ + break; \ + case ' ': \ + isc = 1; *dst++ = '\\'; *dst++ = 's'; \ + break; \ + case '\0': \ + isc = 1; *dst++ = '\\'; *dst++ = '0'; \ + if (isoctal(nextc)) { \ + *dst++ = '0'; \ + *dst++ = '0'; \ + } \ + } \ + } \ + if (isc) break; \ + if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) { \ + *dst++ = '\\'; \ + *dst++ = (u_char)(((unsigned)(u_char)c >> 6) & 03) + '0'; \ + *dst++ = (u_char)(((unsigned)(u_char)c >> 3) & 07) + '0'; \ + *dst++ = (c & 07) + '0'; \ + } else { \ + if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\'; \ + if (c & 0200) { \ + c &= 0177; *dst++ = 'M'; \ + } \ + if (iscntrl((unsigned char)c)) { \ + *dst++ = '^'; \ + if (c == 0177) \ + *dst++ = '?'; \ + else \ + *dst++ = c + '@'; \ + } else { \ + *dst++ = '-'; *dst++ = c; \ + } \ + } \ } while (/*CONSTCOND*/0) diff --git a/kerberosV/src/lib/roken/vis.hin b/kerberosV/src/lib/roken/vis.hin index 2393ad8349a..a2ac48f81d6 100644 --- a/kerberosV/src/lib/roken/vis.hin +++ b/kerberosV/src/lib/roken/vis.hin @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * |