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 /lib/libnv | |
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 'lib/libnv')
-rw-r--r-- | lib/libnv/nv.3 | 50 | ||||
-rw-r--r-- | lib/libnv/tests/nv_tests.cc | 6 | ||||
-rw-r--r-- | lib/libnv/tests/nvlist_send_recv_test.c | 2 |
3 files changed, 47 insertions, 11 deletions
diff --git a/lib/libnv/nv.3 b/lib/libnv/nv.3 index bbb7b03..4c0e236 100644 --- a/lib/libnv/nv.3 +++ b/lib/libnv/nv.3 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 1, 2015 +.Dd May 2, 2015 .Dt NV 3 .Os .Sh NAME @@ -85,14 +85,14 @@ .Ft "void *" .Fn nvlist_pack "const nvlist_t *nvl" "size_t *sizep" .Ft "nvlist_t *" -.Fn nvlist_unpack "const void *buf" "size_t size" +.Fn nvlist_unpack "const void *buf" "size_t size" "int flags" .\" .Ft int .Fn nvlist_send "int sock" "const nvlist_t *nvl" .Ft "nvlist_t *" -.Fn nvlist_recv "int sock" +.Fn nvlist_recv "int sock" "int flags" .Ft "nvlist_t *" -.Fn nvlist_xfer "int sock" "nvlist_t *nvl" +.Fn nvlist_xfer "int sock" "nvlist_t *nvl" "int flags" .\" .Ft "const char *" .Fn nvlist_next "const nvlist_t *nvl" "int *typep" "void **cookiep" @@ -325,6 +325,18 @@ The nvlist must not be in error state. The .Fn nvlist_unpack function converts the given buffer to the nvlist. +The +.Fa flags +argument defines what type of the top level nvlist is expected to be. +Flags are set up using the +.Fn nvlist_create +function. +If the nvlist flags do not match the flags passed to +.Fn nvlist_unpack , +the nvlist will not be returned. +Every nested nvlist list should be checked using +.Fn nvlist_flags +function. The function returns .Dv NULL in case of an error. @@ -343,12 +355,36 @@ The function receives nvlist over the socket given by the .Fa sock argument. +The +.Fa flags +argument defines what type of the top level nvlist is expected to be. +Flags are set up using the +.Fn nvlist_create +function. +If the nvlist flags do not match the flags passed to +.Fn nvlist_recv , +the nvlist will not be returned. +Every nested nvlist list should be checked using +.Fn nvlist_flags +function. .Pp The .Fn nvlist_xfer function sends the given nvlist over the socket given by the .Fa sock argument and receives nvlist over the same socket. +The +.Fa flags +argument defines what type of the top level nvlist is expected to be. +Flags are set up using the +.Fn nvlist_create +function. +If the nvlist flags do not match the flags passed to +.Fn nvlist_xfer , +the nvlist will not be returned. +Every nested nvlist list should be checked using +.Fn nvlist_flags +function. The given nvlist is always destroyed. .Pp The @@ -559,7 +595,7 @@ const char *command; char *filename; int fd; -nvl = nvlist_recv(sock); +nvl = nvlist_recv(sock, 0); if (nvl == NULL) err(1, "nvlist_recv() failed"); @@ -588,7 +624,7 @@ const char *name; void *cookie; int type; -nvl = nvlist_recv(sock); +nvl = nvlist_recv(sock, 0); if (nvl == NULL) err(1, "nvlist_recv() failed"); @@ -617,7 +653,7 @@ const char *name; void *cookie; int type; -nvl = nvlist_recv(sock); +nvl = nvlist_recv(sock, 0); if (nvl == NULL) err(1, "nvlist_recv() failed"); diff --git a/lib/libnv/tests/nv_tests.cc b/lib/libnv/tests/nv_tests.cc index 2d9fd97..1fee182 100644 --- a/lib/libnv/tests/nv_tests.cc +++ b/lib/libnv/tests/nv_tests.cc @@ -440,7 +440,7 @@ ATF_TEST_CASE_BODY(nvlist_pack__empty_nvlist) packed = nvlist_pack(nvl, &packed_size); ATF_REQUIRE(packed != NULL); - unpacked = nvlist_unpack(packed, packed_size); + unpacked = nvlist_unpack(packed, packed_size, 0); ATF_REQUIRE(unpacked != NULL); ATF_REQUIRE(unpacked != nvl); ATF_REQUIRE(nvlist_empty(unpacked)); @@ -534,7 +534,7 @@ ATF_TEST_CASE_BODY(nvlist_pack__multiple_values) packed = nvlist_pack(nvl, &packed_size); ATF_REQUIRE(packed != NULL); - unpacked = nvlist_unpack(packed, packed_size); + unpacked = nvlist_unpack(packed, packed_size, 0); ATF_REQUIRE(unpacked != 0); it = NULL; @@ -614,7 +614,7 @@ ATF_TEST_CASE_BODY(nvlist_unpack__duplicate_key) ATF_REQUIRE(keypos != NULL); memcpy(keypos, key2, keylen); - unpacked = nvlist_unpack(packed, size); + unpacked = nvlist_unpack(packed, size, 0); ATF_REQUIRE(nvlist_error(unpacked) != 0); free(packed); diff --git a/lib/libnv/tests/nvlist_send_recv_test.c b/lib/libnv/tests/nvlist_send_recv_test.c index 1b083c3..50222fb 100644 --- a/lib/libnv/tests/nvlist_send_recv_test.c +++ b/lib/libnv/tests/nvlist_send_recv_test.c @@ -95,7 +95,7 @@ parent(int sock) int type, ctype; size_t size; - nvl = nvlist_recv(sock); + nvl = nvlist_recv(sock, 0); CHECK(nvlist_error(nvl) == 0); if (nvlist_error(nvl) != 0) err(1, "nvlist_recv() failed"); |