diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-08-07 14:56:50 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-09-21 10:29:37 +0200 |
commit | c37f9fba70085fedc8eede7559489d2321393005 (patch) | |
tree | 042455ebf1fa89a277a825f72e1ed805d0b4d296 /freebsd/lib | |
parent | Update to FreeBSD head 2017-06-01 (diff) | |
download | rtems-libbsd-c37f9fba70085fedc8eede7559489d2321393005.tar.bz2 |
Update to FreeBSD head 2017-08-01
Git mirror commit f5002f5e5f78cae9f0269d812dc0aedb0339312c.
Update #3472.
Diffstat (limited to 'freebsd/lib')
-rw-r--r-- | freebsd/lib/libc/include/libc_private.h | 12 | ||||
-rw-r--r-- | freebsd/lib/libc/net/nsdispatch.c | 9 | ||||
-rw-r--r-- | freebsd/lib/libc/rpc/getnetconfig.c | 4 | ||||
-rw-r--r-- | freebsd/lib/libc/rpc/rpc_generic.c | 8 | ||||
-rw-r--r-- | freebsd/lib/libc/rpc/rpcb_clnt.c | 3 | ||||
-rw-r--r-- | freebsd/lib/libc/rpc/rpcb_prot.c | 17 | ||||
-rw-r--r-- | freebsd/lib/libc/rpc/rpcb_st_xdr.c | 9 | ||||
-rw-r--r-- | freebsd/lib/libc/stdio/fgetln.c | 26 | ||||
-rw-r--r-- | freebsd/lib/libc/stdio/local.h | 34 | ||||
-rw-r--r-- | freebsd/lib/libc/xdr/xdr.c | 30 |
10 files changed, 111 insertions, 41 deletions
diff --git a/freebsd/lib/libc/include/libc_private.h b/freebsd/lib/libc/include/libc_private.h index 6ef99342..91f832a0 100644 --- a/freebsd/lib/libc/include/libc_private.h +++ b/freebsd/lib/libc/include/libc_private.h @@ -315,6 +315,7 @@ struct rusage; struct sigaction; struct sockaddr; struct stat; +struct statfs; struct timespec; struct timeval; struct timezone; @@ -331,13 +332,16 @@ int __sys_clock_nanosleep(__clockid_t, int, const struct timespec *, struct timespec *); int __sys_close(int); int __sys_connect(int, const struct sockaddr *, __socklen_t); -__ssize_t __sys_getdirentries(int, char *, __size_t, __off_t *); int __sys_fcntl(int, int, ...); int __sys_fdatasync(int); +int __sys_fstat(int fd, struct stat *); +int __sys_fstatfs(int fd, struct statfs *); int __sys_fstatat(int, const char *, struct stat *, int); int __sys_fsync(int); __pid_t __sys_fork(void); int __sys_ftruncate(int, __off_t); +__ssize_t __sys_getdirentries(int, char *, __size_t, __off_t *); +int __sys_getfsstat(struct statfs *, long, int); int __sys_gettimeofday(struct timeval *, struct timezone *); int __sys_kevent(int, const struct kevent *, int, struct kevent *, int, const struct timespec *); @@ -376,6 +380,7 @@ int __sys_sigtimedwait(const __sigset_t *, struct __siginfo *, const struct timespec *); int __sys_sigwait(const __sigset_t *, int *); int __sys_sigwaitinfo(const __sigset_t *, struct __siginfo *); +int __sys_statfs(const char *, struct statfs *); int __sys_swapcontext(struct __ucontext *, const struct __ucontext *); int __sys_thr_kill(long, int); @@ -414,6 +419,11 @@ void __libc_map_stacks_exec(void); void _pthread_cancel_enter(int); void _pthread_cancel_leave(int); +struct _pthread_cleanup_info; +void ___pthread_cleanup_push_imp(void (*)(void *), void *, + struct _pthread_cleanup_info *); +void ___pthread_cleanup_pop_imp(int); + void __throw_constraint_handler_s(const char * restrict msg, int error); #endif /* _LIBC_PRIVATE_H_ */ diff --git a/freebsd/lib/libc/net/nsdispatch.c b/freebsd/lib/libc/net/nsdispatch.c index f097375d..c739bf6a 100644 --- a/freebsd/lib/libc/net/nsdispatch.c +++ b/freebsd/lib/libc/net/nsdispatch.c @@ -544,7 +544,7 @@ fin: vector_sort(_nsmod, _nsmodsize, sizeof(*_nsmod), string_compare); } - +static int exiting = 0; static void ns_mod_free(ns_mod *mod) @@ -555,12 +555,10 @@ ns_mod_free(ns_mod *mod) return; if (mod->unregister != NULL) mod->unregister(mod->mtab, mod->mtabsize); - if (mod->handle != nss_builtin_handle) + if (mod->handle != nss_builtin_handle && !exiting) (void)dlclose(mod->handle); } - - /* * Cleanup */ @@ -569,6 +567,7 @@ nss_atexit(void) { int isthreaded; + exiting = 1; isthreaded = __isthreaded; if (isthreaded) (void)_pthread_rwlock_wrlock(&nss_lock); @@ -617,8 +616,6 @@ rtems_nss_register_module(const char *source, ns_mtab *mtab, } #endif /* __rtems__ */ - - /* * Finally, the actual implementation. */ diff --git a/freebsd/lib/libc/rpc/getnetconfig.c b/freebsd/lib/libc/rpc/getnetconfig.c index 5e500834..dd3fa87e 100644 --- a/freebsd/lib/libc/rpc/getnetconfig.c +++ b/freebsd/lib/libc/rpc/getnetconfig.c @@ -694,7 +694,7 @@ static struct netconfig * dup_ncp(struct netconfig *ncp) { struct netconfig *p; - char *tmp, *tmp2; + char *tmp; u_int i; if ((tmp=malloc(MAXNETCONFIGLINE)) == NULL) @@ -703,7 +703,6 @@ dup_ncp(struct netconfig *ncp) free(tmp); return(NULL); } - tmp2 = tmp; /* * First we dup all the data from matched netconfig buffer. Then we * adjust some of the member pointer to a pre-allocated buffer where @@ -725,7 +724,6 @@ dup_ncp(struct netconfig *ncp) if (p->nc_lookups == NULL) { free(p->nc_netid); free(p); - free(tmp2); return(NULL); } for (i=0; i < p->nc_nlookups; i++) { diff --git a/freebsd/lib/libc/rpc/rpc_generic.c b/freebsd/lib/libc/rpc/rpc_generic.c index bb8c606b..5bd983c4 100644 --- a/freebsd/lib/libc/rpc/rpc_generic.c +++ b/freebsd/lib/libc/rpc/rpc_generic.c @@ -611,6 +611,8 @@ __rpc_taddr2uaddr_af(int af, const struct netbuf *nbuf) switch (af) { case AF_INET: + if (nbuf->len < sizeof(*sin)) + return NULL; sin = nbuf->buf; if (inet_ntop(af, &sin->sin_addr, namebuf, sizeof namebuf) == NULL) @@ -622,6 +624,8 @@ __rpc_taddr2uaddr_af(int af, const struct netbuf *nbuf) break; #ifdef INET6 case AF_INET6: + if (nbuf->len < sizeof(*sin6)) + return NULL; sin6 = nbuf->buf; if (inet_ntop(af, &sin6->sin6_addr, namebuf6, sizeof namebuf6) == NULL) @@ -660,6 +664,10 @@ __rpc_uaddr2taddr_af(int af, const char *uaddr) port = 0; sin = NULL; + + if (uaddr == NULL) + return NULL; + addrstr = strdup(uaddr); if (addrstr == NULL) return NULL; diff --git a/freebsd/lib/libc/rpc/rpcb_clnt.c b/freebsd/lib/libc/rpc/rpcb_clnt.c index 669c9bec..16cdf20d 100644 --- a/freebsd/lib/libc/rpc/rpcb_clnt.c +++ b/freebsd/lib/libc/rpc/rpcb_clnt.c @@ -500,14 +500,15 @@ try_nconf: hostname = IN6_LOCALHOST_STRING; } } - endnetconfig(nc_handle); if (tmpnconf == NULL) { + endnetconfig(nc_handle); rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; mutex_unlock(&loopnconf_lock); return (NULL); } loopnconf = getnetconfigent(tmpnconf->nc_netid); /* loopnconf is never freed */ + endnetconfig(nc_handle); } mutex_unlock(&loopnconf_lock); client = getclnthandle(hostname, loopnconf, NULL); diff --git a/freebsd/lib/libc/rpc/rpcb_prot.c b/freebsd/lib/libc/rpc/rpcb_prot.c index 95072371..ede13565 100644 --- a/freebsd/lib/libc/rpc/rpcb_prot.c +++ b/freebsd/lib/libc/rpc/rpcb_prot.c @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include <rpc/types.h> #include <rpc/xdr.h> #include <rpc/rpcb_prot.h> +#include <rpc/rpc_com.h> #include "un-namespace.h" bool_t @@ -64,13 +65,13 @@ xdr_rpcb(XDR *xdrs, RPCB *objp) if (!xdr_rpcvers(xdrs, &objp->r_vers)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->r_netid, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_netid, RPC_MAXDATASIZE)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->r_addr, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_addr, RPC_MAXDATASIZE)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->r_owner, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_owner, RPC_MAXDATASIZE)) { return (FALSE); } return (TRUE); @@ -164,19 +165,19 @@ xdr_rpcblist(XDR *xdrs, RPCBLIST **rp) bool_t xdr_rpcb_entry(XDR *xdrs, rpcb_entry *objp) { - if (!xdr_string(xdrs, &objp->r_maddr, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_maddr, RPC_MAXDATASIZE)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->r_nc_netid, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_nc_netid, RPC_MAXDATASIZE)) { return (FALSE); } if (!xdr_u_int32_t(xdrs, &objp->r_nc_semantics)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->r_nc_protofmly, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_nc_protofmly, RPC_MAXDATASIZE)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->r_nc_proto, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->r_nc_proto, RPC_MAXDATASIZE)) { return (FALSE); } return (TRUE); @@ -291,7 +292,7 @@ xdr_rpcb_rmtcallres(XDR *xdrs, struct rpcb_rmtcallres *p) bool_t dummy; struct r_rpcb_rmtcallres *objp = (struct r_rpcb_rmtcallres *)(void *)p; - if (!xdr_string(xdrs, &objp->addr, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->addr, RPC_MAXDATASIZE)) { return (FALSE); } if (!xdr_u_int(xdrs, &objp->results.results_len)) { diff --git a/freebsd/lib/libc/rpc/rpcb_st_xdr.c b/freebsd/lib/libc/rpc/rpcb_st_xdr.c index 6b8711ea..dc5be588 100644 --- a/freebsd/lib/libc/rpc/rpcb_st_xdr.c +++ b/freebsd/lib/libc/rpc/rpcb_st_xdr.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include <rpc/rpc.h> +#include <rpc/rpc_com.h> #include "un-namespace.h" /* Link list of all the stats about getport and getaddr */ @@ -65,7 +66,7 @@ xdr_rpcbs_addrlist(XDR *xdrs, rpcbs_addrlist *objp) if (!xdr_int(xdrs, &objp->failure)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) { return (FALSE); } @@ -117,7 +118,7 @@ xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp) IXDR_PUT_INT32(buf, objp->failure); IXDR_PUT_INT32(buf, objp->indirect); } - if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) { return (FALSE); } pnext = &objp->next; @@ -156,7 +157,7 @@ xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp) objp->failure = (int)IXDR_GET_INT32(buf); objp->indirect = (int)IXDR_GET_INT32(buf); } - if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) { return (FALSE); } if (!xdr_pointer(xdrs, (char **) pnext, @@ -184,7 +185,7 @@ xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp) if (!xdr_int(xdrs, &objp->indirect)) { return (FALSE); } - if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) { + if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) { return (FALSE); } if (!xdr_pointer(xdrs, (char **) pnext, diff --git a/freebsd/lib/libc/stdio/fgetln.c b/freebsd/lib/libc/stdio/fgetln.c index 8d1235c5..7f5e18b3 100644 --- a/freebsd/lib/libc/stdio/fgetln.c +++ b/freebsd/lib/libc/stdio/fgetln.c @@ -87,22 +87,25 @@ char * fgetln(FILE *fp, size_t *lenp) { unsigned char *p; + char *ret; size_t len; size_t off; +#ifndef __rtems__ + FLOCKFILE_CANCELSAFE(fp); +#else /* __rtems__ */ FLOCKFILE(fp); +#endif /* __rtems__ */ ORIENT(fp, -1); /* make sure there is input */ if (fp->_r <= 0 && __srefill(fp)) { *lenp = 0; - FUNLOCKFILE(fp); - return (NULL); + ret = NULL; + goto end; } /* look for a newline in the input */ if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) { - char *ret; - /* * Found one. Flag buffer as modified to keep fseek from * `optimising' a backward seek, in case the user stomps on @@ -116,8 +119,7 @@ fgetln(FILE *fp, size_t *lenp) #endif /* __rtems__ */ fp->_r -= len; fp->_p = p; - FUNLOCKFILE(fp); - return (ret); + goto end; } /* @@ -167,12 +169,18 @@ fgetln(FILE *fp, size_t *lenp) #ifdef notdef fp->_lb._base[len] = '\0'; #endif + ret = (char *)fp->_lb._base; +end: +#ifndef __rtems__ + FUNLOCKFILE_CANCELSAFE(); +#else /* __rtems__ */ FUNLOCKFILE(fp); - return ((char *)fp->_lb._base); +#endif /* __rtems__ */ + return (ret); error: *lenp = 0; /* ??? */ fp->_flags |= __SERR; - FUNLOCKFILE(fp); - return (NULL); /* ??? */ + ret = NULL; + goto end; } diff --git a/freebsd/lib/libc/stdio/local.h b/freebsd/lib/libc/stdio/local.h index 5a7fd577..26a4afe9 100644 --- a/freebsd/lib/libc/stdio/local.h +++ b/freebsd/lib/libc/stdio/local.h @@ -38,6 +38,9 @@ * $FreeBSD$ */ +#ifndef _STDIO_LOCAL_H +#define _STDIO_LOCAL_H + #include <sys/types.h> /* for off_t */ #include <pthread.h> #include <string.h> @@ -65,7 +68,7 @@ extern FILE *__sfp(void); extern int __slbexpand(FILE *, size_t); #ifndef __rtems__ extern int __srefill(FILE *); -#else +#else /* __rtems__ */ /* * __srefill is used by fgetln(). The method is in newlib but the * prototype is in a private .h which is not installed. @@ -74,7 +77,7 @@ extern int __srefill(FILE *); extern int __srefill_r(struct _reent *,FILE *); #define __srefill(_x) __srefill_r(__getreent(), _x) -#endif +#endif /* __rtems__ */ extern int __sread(void *, char *, int); extern int __swrite(void *, char const *, int); extern fpos_t __sseek(void *, fpos_t, int); @@ -155,9 +158,32 @@ __fgetwc(FILE *fp, locale_t locale) */ #ifdef __rtems__ #define ORIENT(fp, o) -#else +#else /* __rtems__ */ #define ORIENT(fp, o) do { \ if ((fp)->_orientation == 0) \ (fp)->_orientation = (o); \ } while (0) -#endif + +void __stdio_cancel_cleanup(void *); +#define FLOCKFILE_CANCELSAFE(fp) \ + { \ + struct _pthread_cleanup_info __cleanup_info__; \ + if (__isthreaded) { \ + _FLOCKFILE(fp); \ + ___pthread_cleanup_push_imp( \ + __stdio_cancel_cleanup, (fp), \ + &__cleanup_info__); \ + } else { \ + ___pthread_cleanup_push_imp( \ + __stdio_cancel_cleanup, NULL, \ + &__cleanup_info__); \ + } \ + { +#define FUNLOCKFILE_CANCELSAFE() \ + (void)0; \ + } \ + ___pthread_cleanup_pop_imp(1); \ + } + +#endif /* __rtems__ */ +#endif /* _STDIO_LOCAL_H */ diff --git a/freebsd/lib/libc/xdr/xdr.c b/freebsd/lib/libc/xdr/xdr.c index c529bb95..877f2efa 100644 --- a/freebsd/lib/libc/xdr/xdr.c +++ b/freebsd/lib/libc/xdr/xdr.c @@ -54,6 +54,8 @@ __FBSDID("$FreeBSD$"); #include <stdlib.h> #include <string.h> +#include <rpc/rpc.h> +#include <rpc/rpc_com.h> #include <rpc/types.h> #include <rpc/xdr.h> #include "un-namespace.h" @@ -66,7 +68,6 @@ typedef u_quad_t u_longlong_t; /* ANSI unsigned long long type */ */ #define XDR_FALSE ((long) 0) #define XDR_TRUE ((long) 1) -#define LASTUNSIGNED ((u_int) 0-1) /* * for unit alignment @@ -561,6 +562,7 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) { char *sp = *cpp; /* sp is the actual string pointer */ u_int nodesize; + bool_t ret, allocated = FALSE; /* * first deal with the length since xdr bytes are counted @@ -584,6 +586,7 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) } if (sp == NULL) { *cpp = sp = mem_alloc(nodesize); + allocated = TRUE; } if (sp == NULL) { warnx("xdr_bytes: out of memory"); @@ -592,7 +595,14 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) /* FALLTHROUGH */ case XDR_ENCODE: - return (xdr_opaque(xdrs, sp, nodesize)); + ret = xdr_opaque(xdrs, sp, nodesize); + if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) { + if (allocated == TRUE) { + free(sp); + *cpp = NULL; + } + } + return (ret); case XDR_FREE: if (sp != NULL) { @@ -683,6 +693,7 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize) char *sp = *cpp; /* sp is the actual string pointer */ u_int size; u_int nodesize; + bool_t ret, allocated = FALSE; /* * first deal with the length since xdr strings are counted-strings @@ -716,8 +727,10 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize) if (nodesize == 0) { return (TRUE); } - if (sp == NULL) + if (sp == NULL) { *cpp = sp = mem_alloc(nodesize); + allocated = TRUE; + } if (sp == NULL) { warnx("xdr_string: out of memory"); return (FALSE); @@ -726,7 +739,14 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize) /* FALLTHROUGH */ case XDR_ENCODE: - return (xdr_opaque(xdrs, sp, size)); + ret = xdr_opaque(xdrs, sp, size); + if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) { + if (allocated == TRUE) { + free(sp); + *cpp = NULL; + } + } + return (ret); case XDR_FREE: mem_free(sp, nodesize); @@ -744,7 +764,7 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize) bool_t xdr_wrapstring(XDR *xdrs, char **cpp) { - return xdr_string(xdrs, cpp, LASTUNSIGNED); + return xdr_string(xdrs, cpp, RPC_MAXDATASIZE); } /* |