diff options
author | oshogbo <oshogbo@FreeBSD.org> | 2015-05-02 17:45:52 +0000 |
---|---|---|
committer | oshogbo <oshogbo@FreeBSD.org> | 2015-05-02 17:45:52 +0000 |
commit | cf66982b37ec7230cc55175c994e05c6176e8e22 (patch) | |
tree | a69b34916c7078793947216a35639f78cd60366e /sys/kern | |
parent | 843dbc5981a1de860cdd7de6cf7aaf65c87a56ab (diff) | |
download | FreeBSD-src-cf66982b37ec7230cc55175c994e05c6176e8e22.zip FreeBSD-src-cf66982b37ec7230cc55175c994e05c6176e8e22.tar.gz |
Approved, oprócz użycie RESTORE_ERRNO() do ustawiania errno.
Change the nvlist_recv() function to take additional argument that
specifies flags expected on the received nvlist. Receiving a nvlist with
different set of flags than the ones we expect might lead to undefined
behaviour, which might be potentially dangerous.
Update consumers of this and related functions and update the tests.
Approved by: pjd (mentor)
Update man page for nvlist_unpack, nvlist_recv, nvlist_xfer, cap_recv_nvlist
and cap_xfer_nvlist.
Reviewed by: AllanJude
Approved by: pjd (mentor)
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/subr_nvlist.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/sys/kern/subr_nvlist.c b/sys/kern/subr_nvlist.c index f96b890..ec44718 100644 --- a/sys/kern/subr_nvlist.c +++ b/sys/kern/subr_nvlist.c @@ -774,7 +774,8 @@ failed: } static nvlist_t * -nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds) +nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds, + int flags) { const unsigned char *ptr; nvlist_t *nvl, *retnvl, *tmpnvl; @@ -782,6 +783,8 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds) size_t left; bool isbe; + PJDLOG_ASSERT((flags & ~(NV_FLAG_PUBLIC_MASK)) == 0); + left = size; ptr = buf; @@ -793,6 +796,10 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds) ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left); if (ptr == NULL) goto failed; + if (nvl->nvl_flags != flags) { + ERRNO_SET(EILSEQ); + goto failed; + } while (left > 0) { ptr = nvpair_unpack(isbe, ptr, &left, &nvp); @@ -849,10 +856,10 @@ failed: } nvlist_t * -nvlist_unpack(const void *buf, size_t size) +nvlist_unpack(const void *buf, size_t size, int flags) { - return (nvlist_xunpack(buf, size, NULL, 0)); + return (nvlist_xunpack(buf, size, NULL, 0, flags)); } #ifndef _KERNEL @@ -900,7 +907,7 @@ out: } nvlist_t * -nvlist_recv(int sock) +nvlist_recv(int sock, int flags) { struct nvlist_header nvlhdr; nvlist_t *nvl, *ret; @@ -937,7 +944,7 @@ nvlist_recv(int sock) goto out; } - nvl = nvlist_xunpack(buf, size, fds, nfds); + nvl = nvlist_xunpack(buf, size, fds, nfds, flags); if (nvl == NULL) { ERRNO_SAVE(); for (i = 0; i < nfds; i++) @@ -957,7 +964,7 @@ out: } nvlist_t * -nvlist_xfer(int sock, nvlist_t *nvl) +nvlist_xfer(int sock, nvlist_t *nvl, int flags) { if (nvlist_send(sock, nvl) < 0) { @@ -965,7 +972,7 @@ nvlist_xfer(int sock, nvlist_t *nvl) return (NULL); } nvlist_destroy(nvl); - return (nvlist_recv(sock)); + return (nvlist_recv(sock, flags)); } #endif |