diff options
Diffstat (limited to 'lib/libc/gen')
-rw-r--r-- | lib/libc/gen/Makefile.inc | 10 | ||||
-rw-r--r-- | lib/libc/gen/Symbol.map | 14 | ||||
-rw-r--r-- | lib/libc/gen/check_utility_compat.c | 12 | ||||
-rw-r--r-- | lib/libc/gen/fmtmsg.c | 2 | ||||
-rw-r--r-- | lib/libc/gen/fstab.c | 12 | ||||
-rw-r--r-- | lib/libc/gen/getbsize.3 | 38 | ||||
-rw-r--r-- | lib/libc/gen/getcap.c | 4 | ||||
-rw-r--r-- | lib/libc/gen/getgrent.c | 8 | ||||
-rw-r--r-- | lib/libc/gen/getnetgrent.c | 4 | ||||
-rw-r--r-- | lib/libc/gen/getttyent.c | 2 | ||||
-rw-r--r-- | lib/libc/gen/getusershell.c | 2 | ||||
-rw-r--r-- | lib/libc/gen/getutxent.c | 2 | ||||
-rw-r--r-- | lib/libc/gen/glob.c | 113 | ||||
-rw-r--r-- | lib/libc/gen/isnan.c | 7 | ||||
-rw-r--r-- | lib/libc/gen/sysctlbyname.c | 9 | ||||
-rw-r--r-- | lib/libc/gen/unvis-compat.c | 46 | ||||
-rw-r--r-- | lib/libc/gen/unvis.3 | 200 | ||||
-rw-r--r-- | lib/libc/gen/unvis.c | 293 | ||||
-rw-r--r-- | lib/libc/gen/vis.3 | 308 | ||||
-rw-r--r-- | lib/libc/gen/vis.c | 201 | ||||
-rw-r--r-- | lib/libc/gen/waitid.c | 65 |
21 files changed, 267 insertions, 1085 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 2481f28..0bbbb33 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -32,13 +32,17 @@ SRCS+= __getosreldate.c __xuname.c \ sigsetops.c sleep.c srand48.c statvfs.c stringlist.c strtofflags.c \ sysconf.c sysctl.c sysctlbyname.c sysctlnametomib.c \ syslog.c telldir.c termios.c time.c times.c timezone.c tls.c \ - ttyname.c ttyslot.c ualarm.c ulimit.c uname.c unvis.c \ - usleep.c utime.c utxdb.c valloc.c vis.c wait.c wait3.c waitpid.c \ - wordexp.c + ttyname.c ttyslot.c ualarm.c ulimit.c uname.c unvis-compat.c \ + usleep.c utime.c utxdb.c valloc.c wait.c wait3.c waitpid.c \ + waitid.c wordexp.c .PATH: ${.CURDIR}/../../contrib/libc-pwcache SRCS+= pwcache.c pwcache.h +.PATH: ${.CURDIR}/../../contrib/libc-vis +CFLAGS+= -I${.CURDIR}/../../contrib/libc-vis +SRCS+= unvis.c vis.c + MISRCS+=modf.c CANCELPOINTS_SRCS=sem.c sem_new.c diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map index b4f88ae..4cbf07c 100644 --- a/lib/libc/gen/Symbol.map +++ b/lib/libc/gen/Symbol.map @@ -298,7 +298,6 @@ FBSD_1.0 { ualarm; ulimit; uname; - unvis; strunvis; strunvisx; usleep; @@ -388,9 +387,22 @@ FBSD_1.3 { __FreeBSD_libc_enter_restricted_mode; getcontextx; gid_from_group; + nvis; pwcache_userdb; pwcache_groupdb; + snvis; + strnunvis; + strnunvisx; + strnvis; + strnvisx; + strsnvis; + strsnvisx; + strsvis; + strsvisx; + svis; uid_from_user; + unvis; + waitid; }; FBSDprivate_1.0 { diff --git a/lib/libc/gen/check_utility_compat.c b/lib/libc/gen/check_utility_compat.c index 0ccdec1..04c594b 100644 --- a/lib/libc/gen/check_utility_compat.c +++ b/lib/libc/gen/check_utility_compat.c @@ -35,32 +35,28 @@ __FBSDID("$FreeBSD$"); * are threaded, so I'm not concerned about cancellation points or other * niceties. */ +#include <sys/limits.h> + #include <limits.h> #include <stdlib.h> #include <string.h> #include <unistd.h> -#ifndef LINE_MAX -#define LINE_MAX _POSIX2_LINE_MAX -#endif - #define _PATH_UTIL_COMPAT "/etc/compat-FreeBSD-4-util" #define _ENV_UTIL_COMPAT "_COMPAT_FreeBSD_4" int check_utility_compat(const char *utility) { - char buf[LINE_MAX]; + char buf[PATH_MAX]; char *p, *bp; int len; if ((p = getenv(_ENV_UTIL_COMPAT)) != NULL) { strlcpy(buf, p, sizeof buf); } else { - if ((len = readlink(_PATH_UTIL_COMPAT, buf, sizeof buf)) < 0) + if ((len = readlink(_PATH_UTIL_COMPAT, buf, sizeof(buf) - 1)) < 0) return 0; - if (len > sizeof buf) - len = sizeof buf; buf[len] = '\0'; } if (buf[0] == '\0') diff --git a/lib/libc/gen/fmtmsg.c b/lib/libc/gen/fmtmsg.c index c6ecbd5..d2c67a6 100644 --- a/lib/libc/gen/fmtmsg.c +++ b/lib/libc/gen/fmtmsg.c @@ -83,7 +83,7 @@ def: if (output == NULL) return (MM_NOCON); if (*output != '\0') { - if ((fp = fopen("/dev/console", "a")) == NULL) { + if ((fp = fopen("/dev/console", "ae")) == NULL) { free(output); return (MM_NOCON); } diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c index b68db2e..6a77abd 100644 --- a/lib/libc/gen/fstab.c +++ b/lib/libc/gen/fstab.c @@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$"); #include <sys/stat.h> #include <errno.h> -#include <fcntl.h> #include <fstab.h> #include <paths.h> #include <stdio.h> @@ -255,8 +254,6 @@ getfsfile(const char *name) int setfsent(void) { - int fd; - if (_fs_fp) { rewind(_fs_fp); LineNo = 0; @@ -268,18 +265,11 @@ setfsent(void) else setfstab(getenv("PATH_FSTAB")); } - fd = _open(path_fstab, O_RDONLY | O_CLOEXEC); - if (fd == -1) { - error(errno); - return (0); - } - _fs_fp = fdopen(fd, "r"); - if (_fs_fp != NULL) { + if ((_fs_fp = fopen(path_fstab, "re")) != NULL) { LineNo = 0; return (1); } error(errno); - _close(fd); return (0); } diff --git a/lib/libc/gen/getbsize.3 b/lib/libc/gen/getbsize.3 index 1407051..2caf5fe 100644 --- a/lib/libc/gen/getbsize.3 +++ b/lib/libc/gen/getbsize.3 @@ -28,12 +28,12 @@ .\" @(#)getbsize.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd November 16, 2012 .Dt GETBSIZE 3 .Os .Sh NAME .Nm getbsize -.Nd get user block size +.Nd get preferred block size .Sh LIBRARY .Lb libc .Sh SYNOPSIS @@ -43,11 +43,31 @@ .Sh DESCRIPTION The .Fn getbsize -function determines the user's preferred block size based on the value of the -.Dq BLOCKSIZE -environment variable; see -.Xr environ 7 -for details on its use and format. +function returns a preferred block size for reporting by system utilities +.Xr df 1 , +.Xr du 1 , +.Xr ls 1 +and +.Xr systat 1 , +based on the value of the +.Ev BLOCKSIZE +environment variable. +.Ev BLOCKSIZE +may be specified directly in bytes, or in multiples of a kilobyte by +specifying a number followed by ``K'' or ``k'', in multiples of a +megabyte by specifying a number followed by ``M'' or ``m'' or in +multiples of a gigabyte by specifying a number followed by ``G'' or +``g''. +Multiples must be integers. +.Pp +Valid values of +.Ev BLOCKSIZE +are 512 bytes to 1 gigabyte. +Sizes less than 512 bytes are rounded up to 512 bytes, and sizes +greater than 1 GB are rounded down to 1 GB. +In each case +.Fn getbsize +produces a warning message. .Pp The .Fn getbsize @@ -61,10 +81,6 @@ terminating null). The memory referenced by .Fa blocksizep is filled in with block size, in bytes. -.Pp -If the user's block size is unreasonable, a warning message is -written to standard error and the returned information reflects -a block size of 512 bytes. .Sh SEE ALSO .Xr df 1 , .Xr du 1 , diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index c321d12..f2f3777 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -654,7 +654,7 @@ cgetnext(char **bp, char **db_array) if (dbp == NULL) dbp = db_array; - if (pfp == NULL && (pfp = fopen(*dbp, "r")) == NULL) { + if (pfp == NULL && (pfp = fopen(*dbp, "re")) == NULL) { (void)cgetclose(); return (-1); } @@ -679,7 +679,7 @@ cgetnext(char **bp, char **db_array) (void)cgetclose(); return (0); } else if ((pfp = - fopen(*dbp, "r")) == NULL) { + fopen(*dbp, "re")) == NULL) { (void)cgetclose(); return (-1); } else diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index 18f64a8..f9480c3 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -810,7 +810,7 @@ files_setgrent(void *retval, void *mdata, va_list ap) if (st->fp != NULL) rewind(st->fp); else if (stayopen) - st->fp = fopen(_PATH_GROUP, "r"); + st->fp = fopen(_PATH_GROUP, "re"); break; case ENDGRENT: if (st->fp != NULL) { @@ -861,7 +861,7 @@ files_group(void *retval, void *mdata, va_list ap) if (*errnop != 0) return (NS_UNAVAIL); if (st->fp == NULL && - ((st->fp = fopen(_PATH_GROUP, "r")) == NULL)) { + ((st->fp = fopen(_PATH_GROUP, "re")) == NULL)) { *errnop = errno; return (NS_UNAVAIL); } @@ -1251,7 +1251,7 @@ compat_setgrent(void *retval, void *mdata, va_list ap) if (st->fp != NULL) rewind(st->fp); else if (stayopen) - st->fp = fopen(_PATH_GROUP, "r"); + st->fp = fopen(_PATH_GROUP, "re"); set_setent(dtab, mdata); (void)_nsdispatch(NULL, dtab, NSDB_GROUP_COMPAT, "setgrent", compatsrc, 0); @@ -1335,7 +1335,7 @@ compat_group(void *retval, void *mdata, va_list ap) if (*errnop != 0) return (NS_UNAVAIL); if (st->fp == NULL && - ((st->fp = fopen(_PATH_GROUP, "r")) == NULL)) { + ((st->fp = fopen(_PATH_GROUP, "re")) == NULL)) { *errnop = errno; rv = NS_UNAVAIL; goto fin; diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c index 51b3e37..4c56461 100644 --- a/lib/libc/gen/getnetgrent.c +++ b/lib/libc/gen/getnetgrent.c @@ -173,7 +173,7 @@ setnetgrent(const char *group) if (((stat(_PATH_NETGROUP, &_yp_statp) < 0) && errno == ENOENT) || _yp_statp.st_size == 0) _use_only_yp = _netgr_yp_enabled = 1; - if ((netf = fopen(_PATH_NETGROUP,"r")) != NULL ||_use_only_yp){ + if ((netf = fopen(_PATH_NETGROUP,"re")) != NULL ||_use_only_yp){ /* * Icky: grab the first character of the netgroup file * and turn on NIS if it's a '+'. rewind the stream @@ -197,7 +197,7 @@ setnetgrent(const char *group) return; } #else - if ((netf = fopen(_PATH_NETGROUP, "r"))) { + if ((netf = fopen(_PATH_NETGROUP, "re"))) { #endif if (parse_netgrp(group)) endnetgrent(); diff --git a/lib/libc/gen/getttyent.c b/lib/libc/gen/getttyent.c index f2fc298..b82c30a 100644 --- a/lib/libc/gen/getttyent.c +++ b/lib/libc/gen/getttyent.c @@ -211,7 +211,7 @@ setttyent(void) if (tf) { rewind(tf); return (1); - } else if ( (tf = fopen(_PATH_TTYS, "r")) ) + } else if ( (tf = fopen(_PATH_TTYS, "re")) ) return (1); return (0); } diff --git a/lib/libc/gen/getusershell.c b/lib/libc/gen/getusershell.c index ce50069..53536e1 100644 --- a/lib/libc/gen/getusershell.c +++ b/lib/libc/gen/getusershell.c @@ -115,7 +115,7 @@ _local_initshells(rv, cb_data, ap) sl_free(sl, 1); sl = sl_init(); - if ((fp = fopen(_PATH_SHELLS, "r")) == NULL) + if ((fp = fopen(_PATH_SHELLS, "re")) == NULL) return NS_UNAVAIL; cp = line; diff --git a/lib/libc/gen/getutxent.c b/lib/libc/gen/getutxent.c index a2e938a..20e8859 100644 --- a/lib/libc/gen/getutxent.c +++ b/lib/libc/gen/getutxent.c @@ -71,7 +71,7 @@ setutxdb(int db, const char *file) if (uf != NULL) fclose(uf); - uf = fopen(file, "r"); + uf = fopen(file, "re"); if (uf == NULL) return (-1); diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c index 211b535..832dc8d 100644 --- a/lib/libc/gen/glob.c +++ b/lib/libc/gen/glob.c @@ -94,6 +94,25 @@ __FBSDID("$FreeBSD$"); #include "collate.h" +/* + * glob(3) expansion limits. Stop the expansion if any of these limits + * is reached. This caps the runtime in the face of DoS attacks. See + * also CVE-2010-2632 + */ +#define GLOB_LIMIT_BRACE 128 /* number of brace calls */ +#define GLOB_LIMIT_PATH 65536 /* number of path elements */ +#define GLOB_LIMIT_READDIR 16384 /* number of readdirs */ +#define GLOB_LIMIT_STAT 1024 /* number of stat system calls */ +#define GLOB_LIMIT_STRING ARG_MAX /* maximum total size for paths */ + +struct glob_limit { + size_t l_brace_cnt; + size_t l_path_lim; + size_t l_readdir_cnt; + size_t l_stat_cnt; + size_t l_string_cnt; +}; + #define DOLLAR '$' #define DOT '.' #define EOS '\0' @@ -153,15 +172,18 @@ static const Char *g_strchr(const Char *, wchar_t); static Char *g_strcat(Char *, const Char *); #endif static int g_stat(Char *, struct stat *, glob_t *); -static int glob0(const Char *, glob_t *, size_t *); -static int glob1(Char *, glob_t *, size_t *); -static int glob2(Char *, Char *, Char *, Char *, glob_t *, size_t *); -static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, size_t *); -static int globextend(const Char *, glob_t *, size_t *); -static const Char * +static int glob0(const Char *, glob_t *, struct glob_limit *); +static int glob1(Char *, glob_t *, struct glob_limit *); +static int glob2(Char *, Char *, Char *, Char *, glob_t *, + struct glob_limit *); +static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, + struct glob_limit *); +static int globextend(const Char *, glob_t *, struct glob_limit *); +static const Char * globtilde(const Char *, Char *, size_t, glob_t *); -static int globexp1(const Char *, glob_t *, size_t *); -static int globexp2(const Char *, const Char *, glob_t *, int *, size_t *); +static int globexp1(const Char *, glob_t *, struct glob_limit *); +static int globexp2(const Char *, const Char *, glob_t *, int *, + struct glob_limit *); static int match(Char *, Char *, Char *); #ifdef DEBUG static void qprintf(const char *, Char *); @@ -171,8 +193,8 @@ int glob(const char * __restrict pattern, int flags, int (*errfunc)(const char *, int), glob_t * __restrict pglob) { + struct glob_limit limit = { 0, 0, 0, 0, 0 }; const char *patnext; - size_t limit; Char *bufnext, *bufend, patbuf[MAXPATHLEN], prot; mbstate_t mbs; wchar_t wc; @@ -186,11 +208,10 @@ glob(const char * __restrict pattern, int flags, pglob->gl_offs = 0; } if (flags & GLOB_LIMIT) { - limit = pglob->gl_matchc; - if (limit == 0) - limit = ARG_MAX; - } else - limit = 0; + limit.l_path_lim = pglob->gl_matchc; + if (limit.l_path_lim == 0) + limit.l_path_lim = GLOB_LIMIT_PATH; + } pglob->gl_flags = flags & ~GLOB_MAGCHAR; pglob->gl_errfunc = errfunc; pglob->gl_matchc = 0; @@ -243,11 +264,17 @@ glob(const char * __restrict pattern, int flags, * characters */ static int -globexp1(const Char *pattern, glob_t *pglob, size_t *limit) +globexp1(const Char *pattern, glob_t *pglob, struct glob_limit *limit) { const Char* ptr = pattern; int rv; + if ((pglob->gl_flags & GLOB_LIMIT) && + limit->l_brace_cnt++ >= GLOB_LIMIT_BRACE) { + errno = 0; + return (GLOB_NOSPACE); + } + /* Protect a single {}, for find(1), like csh */ if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) return glob0(pattern, pglob, limit); @@ -266,7 +293,8 @@ globexp1(const Char *pattern, glob_t *pglob, size_t *limit) * If it fails then it tries to glob the rest of the pattern and returns. */ static int -globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv, size_t *limit) +globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv, + struct glob_limit *limit) { int i; Char *lm, *ls; @@ -436,7 +464,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob) * if things went well, nonzero if errors occurred. */ static int -glob0(const Char *pattern, glob_t *pglob, size_t *limit) +glob0(const Char *pattern, glob_t *pglob, struct glob_limit *limit) { const Char *qpatnext; int err; @@ -529,7 +557,7 @@ compare(const void *p, const void *q) } static int -glob1(Char *pattern, glob_t *pglob, size_t *limit) +glob1(Char *pattern, glob_t *pglob, struct glob_limit *limit) { Char pathbuf[MAXPATHLEN]; @@ -547,7 +575,7 @@ glob1(Char *pattern, glob_t *pglob, size_t *limit) */ static int glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern, - glob_t *pglob, size_t *limit) + glob_t *pglob, struct glob_limit *limit) { struct stat sb; Char *p, *q; @@ -563,6 +591,15 @@ glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern, if (g_lstat(pathbuf, &sb, pglob)) return (0); + if ((pglob->gl_flags & GLOB_LIMIT) && + limit->l_stat_cnt++ >= GLOB_LIMIT_STAT) { + errno = 0; + if (pathend + 1 > pathend_last) + return (GLOB_ABORTED); + *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) && @@ -606,7 +643,7 @@ glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern, static int glob3(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern, Char *restpattern, - glob_t *pglob, size_t *limit) + glob_t *pglob, struct glob_limit *limit) { struct dirent *dp; DIR *dirp; @@ -652,6 +689,19 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last, size_t clen; mbstate_t mbs; + if ((pglob->gl_flags & GLOB_LIMIT) && + limit->l_readdir_cnt++ >= GLOB_LIMIT_READDIR) { + errno = 0; + if (pathend + 1 > pathend_last) + err = GLOB_ABORTED; + else { + *pathend++ = SEP; + *pathend = EOS; + err = GLOB_NOSPACE; + } + break; + } + /* Initial DOT must be matched literally. */ if (dp->d_name[0] == DOT && *pattern != DOT) continue; @@ -702,29 +752,24 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last, * gl_pathv points to (gl_offs + gl_pathc + 1) items. */ static int -globextend(const Char *path, glob_t *pglob, size_t *limit) +globextend(const Char *path, glob_t *pglob, struct glob_limit *limit) { char **pathv; size_t i, newsize, len; char *copy; const Char *p; - if (*limit && pglob->gl_pathc > *limit) { + if ((pglob->gl_flags & GLOB_LIMIT) && + pglob->gl_matchc > limit->l_path_lim) { errno = 0; return (GLOB_NOSPACE); } newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs); - pathv = pglob->gl_pathv ? - realloc((char *)pglob->gl_pathv, newsize) : - malloc(newsize); - if (pathv == NULL) { - if (pglob->gl_pathv) { - free(pglob->gl_pathv); - pglob->gl_pathv = NULL; - } + /* realloc(NULL, newsize) is equivalent to malloc(newsize). */ + pathv = realloc((void *)pglob->gl_pathv, newsize); + if (pathv == NULL) return (GLOB_NOSPACE); - } if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { /* first time around -- clear initial gl_offs items */ @@ -737,6 +782,12 @@ globextend(const Char *path, glob_t *pglob, size_t *limit) for (p = path; *p++;) continue; len = MB_CUR_MAX * (size_t)(p - path); /* XXX overallocation */ + limit->l_string_cnt += len; + if ((pglob->gl_flags & GLOB_LIMIT) && + limit->l_string_cnt >= GLOB_LIMIT_STRING) { + errno = 0; + return (GLOB_NOSPACE); + } if ((copy = malloc(len)) != NULL) { if (g_Ctoc(path, copy, len)) { free(copy); diff --git a/lib/libc/gen/isnan.c b/lib/libc/gen/isnan.c index ec81362..72c2868 100644 --- a/lib/libc/gen/isnan.c +++ b/lib/libc/gen/isnan.c @@ -33,8 +33,14 @@ /* * XXX These routines belong in libm, but they must remain in libc for * binary compat until we can bump libm's major version number. + * + * Note this only applies to the dynamic versions of libm and libc, so + * for the static and profiled versions we stub out the definitions. + * Otherwise you cannot link statically to libm and libc at the same + * time, when calling both functions. */ +#ifdef PIC __weak_reference(__isnan, isnan); __weak_reference(__isnanf, isnanf); @@ -55,3 +61,4 @@ __isnanf(float f) u.f = f; return (u.bits.exp == 255 && u.bits.man != 0); } +#endif /* PIC */ diff --git a/lib/libc/gen/sysctlbyname.c b/lib/libc/gen/sysctlbyname.c index a2e0d5f..88b860d 100644 --- a/lib/libc/gen/sysctlbyname.c +++ b/lib/libc/gen/sysctlbyname.c @@ -19,13 +19,10 @@ sysctlbyname(const char *name, void *oldp, size_t *oldlenp, const void *newp, size_t newlen) { int real_oid[CTL_MAXNAME+2]; - int error; size_t oidlen; oidlen = sizeof(real_oid) / sizeof(int); - error = sysctlnametomib(name, real_oid, &oidlen); - if (error < 0) - return (error); - error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen); - return (error); + if (sysctlnametomib(name, real_oid, &oidlen) < 0) + return (-1); + return (sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen)); } diff --git a/lib/libc/gen/unvis-compat.c b/lib/libc/gen/unvis-compat.c new file mode 100644 index 0000000..080143e --- /dev/null +++ b/lib/libc/gen/unvis-compat.c @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 2012 SRI International + * All rights reserved. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include <vis.h> + +#define _UNVIS_END 1 + +int +__unvis_44bsd(char *cp, int c, int *astate, int flag) +{ + + if (flag & _UNVIS_END) + flag = (flag & ~_UNVIS_END) ^ UNVIS_END; + return unvis(cp, c, astate, flag); +} + +__sym_compat(unvis, __vis_44bsd, FBSD_1.0); diff --git a/lib/libc/gen/unvis.3 b/lib/libc/gen/unvis.3 deleted file mode 100644 index 9164f79..0000000 --- a/lib/libc/gen/unvis.3 +++ /dev/null @@ -1,200 +0,0 @@ -.\" Copyright (c) 1989, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 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. -.\" 4. 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. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)unvis.3 8.2 (Berkeley) 12/11/93 -.\" $FreeBSD$ -.\" -.Dd December 11, 1993 -.Dt UNVIS 3 -.Os -.Sh NAME -.Nm unvis , -.Nm strunvis -.Nd decode a visual representation of characters -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In vis.h -.Ft int -.Fn unvis "char *cp" "int c" "int *astate" "int flag" -.Ft int -.Fn strunvis "char *dst" "const char *src" -.Ft int -.Fn strunvisx "char *dst" "const char *src" "int flag" -.Sh DESCRIPTION -The -.Fn unvis , -.Fn strunvis -and -.Fn strunvisx -functions -are used to decode a visual representation of characters, as produced -by the -.Xr vis 3 -function, back into -the original form. -Unvis is called with successive characters in -.Fa c -until a valid -sequence is recognized, at which time the decoded character is -available at the character pointed to by -.Fa cp . -Strunvis decodes the -characters pointed to by -.Fa src -into the buffer pointed to by -.Fa dst . -.Pp -The -.Fn strunvis -function -simply copies -.Fa src -to -.Fa dst , -decoding any escape sequences along the way, -and returns the number of characters placed into -.Fa dst , -or \-1 if an -invalid escape sequence was detected. -The size of -.Fa dst -should be -equal to the size of -.Fa src -(that is, no expansion takes place during -decoding). -.Pp -The -.Fn strunvisx -function does the same as the -.Fn strunvis -function, -but it allows you to add a flag that specifies the style the string -.Fa src -is encoded with. -Currently, the only supported flag is -.Dv VIS_HTTPSTYLE . -.Pp -The -.Fn unvis -function -implements a state machine that can be used to decode an arbitrary -stream of bytes. -All state associated with the bytes being decoded -is stored outside the -.Fn unvis -function (that is, a pointer to the state is passed in), so -calls decoding different streams can be freely intermixed. -To -start decoding a stream of bytes, first initialize an integer -to zero. -Call -.Fn unvis -with each successive byte, along with a pointer -to this integer, and a pointer to a destination character. -The -.Fn unvis -function -has several return codes that must be handled properly. -They are: -.Bl -tag -width UNVIS_VALIDPUSH -.It Li \&0 (zero) -Another character is necessary; nothing has been recognized yet. -.It Dv UNVIS_VALID -A valid character has been recognized and is available at the location -pointed to by cp. -.It Dv UNVIS_VALIDPUSH -A valid character has been recognized and is available at the location -pointed to by cp; however, the character currently passed in should -be passed in again. -.It Dv UNVIS_NOCHAR -A valid sequence was detected, but no character was produced. -This -return code is necessary to indicate a logical break between characters. -.It Dv UNVIS_SYNBAD -An invalid escape sequence was detected, or the decoder is in an -unknown state. -The decoder is placed into the starting state. -.El -.Pp -When all bytes in the stream have been processed, call -.Fn unvis -one more time with -.Fa flag -set to -.Dv UNVIS_END -to extract any remaining character (the character passed in is ignored). -.Pp -The -.Fa flag -argument is also used to specify the encoding style of the source. -If set to -.Dv VIS_HTTPSTYLE , -.Fn unvis -will decode URI strings as specified in RFC 1808. -.Pp -The following code fragment illustrates a proper use of -.Fn unvis . -.Bd -literal -offset indent -int state = 0; -char out; - -while ((ch = getchar()) != EOF) { -again: - switch(unvis(&out, ch, &state, 0)) { - case 0: - case UNVIS_NOCHAR: - break; - case UNVIS_VALID: - (void) putchar(out); - break; - case UNVIS_VALIDPUSH: - (void) putchar(out); - goto again; - case UNVIS_SYNBAD: - (void)fprintf(stderr, "bad sequence!\en"); - exit(1); - } -} -if (unvis(&out, (char)0, &state, UNVIS_END) == UNVIS_VALID) - (void) putchar(out); -.Ed -.Sh SEE ALSO -.Xr vis 1 , -.Xr vis 3 -.Rs -.%A R. Fielding -.%T Relative Uniform Resource Locators -.%O RFC1808 -.Re -.Sh HISTORY -The -.Fn unvis -function -first appeared in -.Bx 4.4 . diff --git a/lib/libc/gen/unvis.c b/lib/libc/gen/unvis.c deleted file mode 100644 index 9069e55..0000000 --- a/lib/libc/gen/unvis.c +++ /dev/null @@ -1,293 +0,0 @@ -/*- - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 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. - * 4. 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. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/types.h> -#include <ctype.h> -#include <vis.h> - -/* - * decode driven by state machine - */ -#define S_GROUND 0 /* haven't seen escape char */ -#define S_START 1 /* start decoding special sequence */ -#define S_META 2 /* metachar started (M) */ -#define S_META1 3 /* metachar more, regular char (-) */ -#define S_CTRL 4 /* control char started (^) */ -#define S_OCTAL2 5 /* octal digit 2 */ -#define S_OCTAL3 6 /* octal digit 3 */ -#define S_HEX2 7 /* hex digit 2 */ - -#define S_HTTP 0x080 /* %HEXHEX escape */ - -#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') -#define ishex(c) ((((u_char)(c)) >= '0' && ((u_char)(c)) <= '9') || (((u_char)(c)) >= 'a' && ((u_char)(c)) <= 'f')) - -/* - * unvis - decode characters previously encoded by vis - */ -int -unvis(char *cp, int c, int *astate, int flag) -{ - - if (flag & UNVIS_END) { - if (*astate == S_OCTAL2 || *astate == S_OCTAL3) { - *astate = S_GROUND; - return (UNVIS_VALID); - } - return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD); - } - - switch (*astate & ~S_HTTP) { - - case S_GROUND: - *cp = 0; - if (c == '\\') { - *astate = S_START; - return (0); - } - if (flag & VIS_HTTPSTYLE && c == '%') { - *astate = S_START | S_HTTP; - return (0); - } - *cp = c; - return (UNVIS_VALID); - - case S_START: - if (*astate & S_HTTP) { - if (ishex(tolower(c))) { - *cp = isdigit(c) ? (c - '0') : (tolower(c) - 'a'); - *astate = S_HEX2; - return (0); - } - } - switch(c) { - case '\\': - *cp = c; - *astate = S_GROUND; - return (UNVIS_VALID); - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - *cp = (c - '0'); - *astate = S_OCTAL2; - return (0); - case 'M': - *cp = 0200; - *astate = S_META; - return (0); - case '^': - *astate = S_CTRL; - return (0); - case 'n': - *cp = '\n'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'r': - *cp = '\r'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'b': - *cp = '\b'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'a': - *cp = '\007'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'v': - *cp = '\v'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 't': - *cp = '\t'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'f': - *cp = '\f'; - *astate = S_GROUND; - return (UNVIS_VALID); - case 's': - *cp = ' '; - *astate = S_GROUND; - return (UNVIS_VALID); - case 'E': - *cp = '\033'; - *astate = S_GROUND; - return (UNVIS_VALID); - case '\n': - /* - * hidden newline - */ - *astate = S_GROUND; - return (UNVIS_NOCHAR); - case '$': - /* - * hidden marker - */ - *astate = S_GROUND; - return (UNVIS_NOCHAR); - } - *astate = S_GROUND; - return (UNVIS_SYNBAD); - - case S_META: - if (c == '-') - *astate = S_META1; - else if (c == '^') - *astate = S_CTRL; - else { - *astate = S_GROUND; - return (UNVIS_SYNBAD); - } - return (0); - - case S_META1: - *astate = S_GROUND; - *cp |= c; - return (UNVIS_VALID); - - case S_CTRL: - if (c == '?') - *cp |= 0177; - else - *cp |= c & 037; - *astate = S_GROUND; - return (UNVIS_VALID); - - case S_OCTAL2: /* second possible octal digit */ - if (isoctal(c)) { - /* - * yes - and maybe a third - */ - *cp = (*cp << 3) + (c - '0'); - *astate = S_OCTAL3; - return (0); - } - /* - * no - done with current sequence, push back passed char - */ - *astate = S_GROUND; - return (UNVIS_VALIDPUSH); - - case S_OCTAL3: /* third possible octal digit */ - *astate = S_GROUND; - if (isoctal(c)) { - *cp = (*cp << 3) + (c - '0'); - return (UNVIS_VALID); - } - /* - * we were done, push back passed char - */ - return (UNVIS_VALIDPUSH); - - case S_HEX2: /* second mandatory hex digit */ - if (ishex(tolower(c))) { - *cp = (isdigit(c) ? (*cp << 4) + (c - '0') : (*cp << 4) + (tolower(c) - 'a' + 10)); - } - *astate = S_GROUND; - return (UNVIS_VALID); - - default: - /* - * decoder in unknown state - (probably uninitialized) - */ - *astate = S_GROUND; - return (UNVIS_SYNBAD); - } -} - -/* - * strunvis - decode src into dst - * - * Number of chars decoded into dst is returned, -1 on error. - * Dst is null terminated. - */ - -int -strunvis(char *dst, const char *src) -{ - char c; - char *start = dst; - int state = 0; - - while ( (c = *src++) ) { - again: - switch (unvis(dst, c, &state, 0)) { - case UNVIS_VALID: - dst++; - break; - case UNVIS_VALIDPUSH: - dst++; - goto again; - case 0: - case UNVIS_NOCHAR: - break; - default: - return (-1); - } - } - if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID) - dst++; - *dst = '\0'; - return (dst - start); -} - -int -strunvisx(char *dst, const char *src, int flag) -{ - char c; - char *start = dst; - int state = 0; - - while ( (c = *src++) ) { - again: - switch (unvis(dst, c, &state, flag)) { - case UNVIS_VALID: - dst++; - break; - case UNVIS_VALIDPUSH: - dst++; - goto again; - case 0: - case UNVIS_NOCHAR: - break; - default: - return (-1); - } - } - if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID) - dst++; - *dst = '\0'; - return (dst - start); -} diff --git a/lib/libc/gen/vis.3 b/lib/libc/gen/vis.3 deleted file mode 100644 index 8ec16eb..0000000 --- a/lib/libc/gen/vis.3 +++ /dev/null @@ -1,308 +0,0 @@ -.\" Copyright (c) 1989, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 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. -.\" 4. 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. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" From: @(#)vis.3 8.1 (Berkeley) 6/9/93 -.\" $FreeBSD$ -.\" -.Dd April 9, 2006 -.Dt VIS 3 -.Os -.Sh NAME -.Nm vis -.Nd visually encode characters -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In vis.h -.Ft char * -.Fn vis "char *dst" "int c" "int flag" "int nextc" -.Ft int -.Fn strvis "char *dst" "const char *src" "int flag" -.Ft int -.Fn strvisx "char *dst" "const char *src" "size_t len" "int flag" -.Sh DESCRIPTION -The -.Fn vis -function -copies into -.Fa dst -a string which represents the character -.Fa c . -If -.Fa c -needs no encoding, it is copied in unaltered. -The string is -null terminated, and a pointer to the end of the string is -returned. -The maximum length of any encoding is four -characters (not including the trailing -.Dv NUL ) ; -thus, when -encoding a set of characters into a buffer, the size of the buffer should -be four times the number of characters encoded, plus one for the trailing -.Dv NUL . -The -.Fa flag -argument is used for altering the default range of -characters considered for encoding and for altering the visual -representation. -The additional character, -.Fa nextc , -is only used when selecting the -.Dv VIS_CSTYLE -encoding format (explained below). -.Pp -The -.Fn strvis -and -.Fn strvisx -functions copy into -.Fa dst -a visual representation of -the string -.Fa src . -The -.Fn strvis -function encodes characters from -.Fa src -up to the -first -.Dv NUL . -The -.Fn strvisx -function encodes exactly -.Fa len -characters from -.Fa src -(this -is useful for encoding a block of data that may contain -.Dv NUL Ns 's ) . -Both forms -.Dv NUL -terminate -.Fa dst . -The size of -.Fa dst -must be four times the number -of characters encoded from -.Fa src -(plus one for the -.Dv NUL ) . -Both -forms return the number of characters in dst (not including -the trailing -.Dv NUL ) . -.Pp -The encoding is a unique, invertible representation composed entirely of -graphic characters; it can be decoded back into the original form using -the -.Xr unvis 3 -or -.Xr strunvis 3 -functions. -.Pp -There are two parameters that can be controlled: the range of -characters that are encoded, and the type -of representation used. -By default, all non-graphic characters -except space, tab, and newline are encoded. -(See -.Xr isgraph 3 . ) -The following flags -alter this: -.Bl -tag -width VIS_WHITEX -.It Dv VIS_GLOB -Also encode magic characters -.Ql ( * , -.Ql \&? , -.Ql \&[ -and -.Ql # ) -recognized by -.Xr glob 3 . -.It Dv VIS_SP -Also encode space. -.It Dv VIS_TAB -Also encode tab. -.It Dv VIS_NL -Also encode newline. -.It Dv VIS_WHITE -Synonym for -.Dv VIS_SP -\&| -.Dv VIS_TAB -\&| -.Dv VIS_NL . -.It Dv VIS_SAFE -Only encode "unsafe" characters. -Unsafe means control -characters which may cause common terminals to perform -unexpected functions. -Currently this form allows space, -tab, newline, backspace, bell, and return - in addition -to all graphic characters - unencoded. -.El -.Pp -There are four forms of encoding. -Most forms use the backslash character -.Ql \e -to introduce a special -sequence; two backslashes are used to represent a real backslash. -These are the visual formats: -.Bl -tag -width VIS_HTTPSTYLE -.It (default) -Use an -.Ql M -to represent meta characters (characters with the 8th -bit set), and use caret -.Ql ^ -to represent control characters see -.Pf ( Xr iscntrl 3 ) . -The following formats are used: -.Bl -tag -width xxxxx -.It Dv \e^C -Represents the control character -.Ql C . -Spans characters -.Ql \e000 -through -.Ql \e037 , -and -.Ql \e177 -(as -.Ql \e^? ) . -.It Dv \eM-C -Represents character -.Ql C -with the 8th bit set. -Spans characters -.Ql \e241 -through -.Ql \e376 . -.It Dv \eM^C -Represents control character -.Ql C -with the 8th bit set. -Spans characters -.Ql \e200 -through -.Ql \e237 , -and -.Ql \e377 -(as -.Ql \eM^? ) . -.It Dv \e040 -Represents -.Tn ASCII -space. -.It Dv \e240 -Represents Meta-space. -.El -.Pp -.It Dv VIS_CSTYLE -Use C-style backslash sequences to represent standard non-printable -characters. -The following sequences are used to represent the indicated characters: -.Pp -.Bl -tag -width ".Li \e0" -offset indent -compact -.It Li \ea -.Dv BEL No (007) -.It Li \eb -.Dv BS No (010) -.It Li \ef -.Dv NP No (014) -.It Li \en -.Dv NL No (012) -.It Li \er -.Dv CR No (015) -.It Li \es -.Dv SP No (040) -.It Li \et -.Dv HT No (011) -.It Li \ev -.Dv VT No (013) -.It Li \e0 -.Dv NUL No (000) -.El -.Pp -When using this format, the -.Fa nextc -argument is looked at to determine -if a -.Dv NUL -character can be encoded as -.Ql \e0 -instead of -.Ql \e000 . -If -.Fa nextc -is an octal digit, the latter representation is used to -avoid ambiguity. -.It Dv VIS_HTTPSTYLE -Use URI encoding as described in RFC 1808. -The form is -.Ql %dd -where -.Ar d -represents a hexadecimal digit. -.It Dv VIS_OCTAL -Use a three digit octal sequence. -The form is -.Ql \eddd -where -.Ar d -represents an octal digit. -.El -.Pp -There is one additional flag, -.Dv VIS_NOSLASH , -which inhibits the -doubling of backslashes and the backslash before the default -format (that is, control characters are represented by -.Ql ^C -and -meta characters as -.Ql M-C ) . -With this flag set, the encoding is -ambiguous and non-invertible. -.Sh SEE ALSO -.Xr unvis 1 , -.Xr unvis 3 -.Rs -.%A R. Fielding -.%T Relative Uniform Resource Locators -.%O RFC1808 -.Re -.Sh HISTORY -These functions first appeared in -.Bx 4.4 . -.Sh BUGS -The -.Nm -family of functions do not recognize multibyte characters, and thus -may consider them to be non-printable when they are in fact printable -(and vice versa.) diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c deleted file mode 100644 index 362f4dc..0000000 --- a/lib/libc/gen/vis.c +++ /dev/null @@ -1,201 +0,0 @@ -/*- - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 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. - * 4. 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. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)vis.c 8.1 (Berkeley) 7/19/93"; -#endif /* LIBC_SCCS and not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/types.h> -#include <limits.h> -#include <ctype.h> -#include <stdio.h> -#include <vis.h> - -#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') - -/* - * vis - visually encode characters - */ -char * -vis(dst, c, flag, nextc) - char *dst; - int c, nextc; - int flag; -{ - c = (unsigned char)c; - - if (flag & VIS_HTTPSTYLE) { - /* Described in RFC 1808 */ - if (!(isalnum(c) /* alpha-numeric */ - /* safe */ - || c == '$' || c == '-' || c == '_' || c == '.' || c == '+' - /* extra */ - || c == '!' || c == '*' || c == '\'' || c == '(' - || c == ')' || c == ',')) { - *dst++ = '%'; - snprintf(dst, 4, (c < 16 ? "0%X" : "%X"), c); - dst += 2; - goto done; - } - } - - if ((flag & VIS_GLOB) && - (c == '*' || c == '?' || c == '[' || c == '#')) - ; - else if (isgraph(c) || - ((flag & VIS_SP) == 0 && c == ' ') || - ((flag & VIS_TAB) == 0 && c == '\t') || - ((flag & VIS_NL) == 0 && c == '\n') || - ((flag & VIS_SAFE) && (c == '\b' || c == '\007' || c == '\r'))) { - *dst++ = c; - if (c == '\\' && (flag & VIS_NOSLASH) == 0) - *dst++ = '\\'; - *dst = '\0'; - return (dst); - } - - if (flag & VIS_CSTYLE) { - switch(c) { - case '\n': - *dst++ = '\\'; - *dst++ = 'n'; - goto done; - case '\r': - *dst++ = '\\'; - *dst++ = 'r'; - goto done; - case '\b': - *dst++ = '\\'; - *dst++ = 'b'; - goto done; - case '\a': - *dst++ = '\\'; - *dst++ = 'a'; - goto done; - case '\v': - *dst++ = '\\'; - *dst++ = 'v'; - goto done; - case '\t': - *dst++ = '\\'; - *dst++ = 't'; - goto done; - case '\f': - *dst++ = '\\'; - *dst++ = 'f'; - goto done; - case ' ': - *dst++ = '\\'; - *dst++ = 's'; - goto done; - case '\0': - *dst++ = '\\'; - *dst++ = '0'; - if (isoctal(nextc)) { - *dst++ = '0'; - *dst++ = '0'; - } - goto done; - } - } - if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) { - *dst++ = '\\'; - *dst++ = ((u_char)c >> 6 & 07) + '0'; - *dst++ = ((u_char)c >> 3 & 07) + '0'; - *dst++ = ((u_char)c & 07) + '0'; - goto done; - } - 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; - } -done: - *dst = '\0'; - return (dst); -} - -/* - * strvis, strvisx - visually encode characters from src into dst - * - * Dst must be 4 times the size of src to account for possible - * expansion. The length of dst, not including the trailing NUL, - * is returned. - * - * Strvisx encodes exactly len bytes from src into dst. - * This is useful for encoding a block of data. - */ -int -strvis(dst, src, flag) - char *dst; - const char *src; - int flag; -{ - char c; - char *start; - - for (start = dst; (c = *src); ) - dst = vis(dst, c, flag, *++src); - *dst = '\0'; - return (dst - start); -} - -int -strvisx(dst, src, len, flag) - char *dst; - const char *src; - size_t len; - int flag; -{ - int c; - char *start; - - for (start = dst; len > 1; len--) { - c = *src; - dst = vis(dst, c, flag, *++src); - } - if (len) - dst = vis(dst, *src, flag, '\0'); - *dst = '\0'; - - return (dst - start); -} diff --git a/lib/libc/gen/waitid.c b/lib/libc/gen/waitid.c new file mode 100644 index 0000000..795b208 --- /dev/null +++ b/lib/libc/gen/waitid.c @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 2012 Jukka A. Ukkonen + * All rights reserved. + * + * This software was developed by Jukka Ukkonen for FreeBSD. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include "namespace.h" +#include <sys/types.h> +#include <sys/wait.h> +#include <stddef.h> +#include <string.h> +#include <signal.h> +#include <errno.h> +#include "un-namespace.h" + +int +__waitid(idtype_t idtype, id_t id, siginfo_t *info, int flags) +{ + int status; + pid_t ret; + + ret = _wait6(idtype, id, &status, flags, NULL, info); + + /* + * According to SUSv4, waitid() shall not return a PID when a + * process is found, but only 0. If a process was actually + * found, siginfo_t fields si_signo and si_pid will be + * non-zero. In case WNOHANG was set in the flags and no + * process was found those fields are set to zero using + * memset() below. + */ + if (ret == 0 && info != NULL) + memset(info, 0, sizeof(*info)); + else if (ret > 0) + ret = 0; + return (ret); +} + +__weak_reference(__waitid, waitid); +__weak_reference(__waitid, _waitid); |