Index: lib/libnv/tests/nvlist_send_recv_test.c =================================================================== --- lib/libnv/tests/nvlist_send_recv_test.c +++ lib/libnv/tests/nvlist_send_recv_test.c @@ -58,8 +58,10 @@ child(int sock) { nvlist_t *nvl; + nvlist_t *empty; nvl = nvlist_create(0); + empty = nvlist_create(0); nvlist_add_bool(nvl, "nvlist/bool/true", true); nvlist_add_bool(nvl, "nvlist/bool/false", false); @@ -75,6 +77,7 @@ nvlist_add_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO", STDERR_FILENO); nvlist_add_binary(nvl, "nvlist/binary/x", "x", 1); nvlist_add_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")); + nvlist_move_nvlist(nvl, "nvlist/nvlist/empty", empty); nvlist_add_nvlist(nvl, "nvlist/nvlist", nvl); nvlist_send(sock, nvl); @@ -86,7 +89,7 @@ parent(int sock) { nvlist_t *nvl; - const nvlist_t *cnvl; + const nvlist_t *cnvl, *empty; const char *name, *cname; void *cookie, *ccookie; int type, ctype; @@ -190,6 +193,13 @@ name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_NVLIST); + CHECK(strcmp(name, "nvlist/nvlist/empty") == 0); + cnvl = nvlist_get_nvlist(nvl, name); + CHECK(nvlist_empty(cnvl)); + + name = nvlist_next(nvl, &type, &cookie); + CHECK(name != NULL); + CHECK(type == NV_TYPE_NVLIST); CHECK(strcmp(name, "nvlist/nvlist") == 0); cnvl = nvlist_get_nvlist(nvl, name); @@ -284,6 +294,13 @@ CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz")); cname = nvlist_next(cnvl, &ctype, &ccookie); + CHECK(cname != NULL); + CHECK(ctype == NV_TYPE_NVLIST); + CHECK(strcmp(cname, "nvlist/nvlist/empty") == 0); + empty = nvlist_get_nvlist(cnvl, cname); + CHECK(nvlist_empty(empty)); + + cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname == NULL); name = nvlist_next(nvl, &type, &cookie); Index: sys/kern/subr_nvlist.c =================================================================== --- sys/kern/subr_nvlist.c +++ sys/kern/subr_nvlist.c @@ -364,12 +364,15 @@ nvl = nvpair_get_nvlist(nvp); PJDLOG_ASSERT(nvl->nvl_error == 0); nvp = nvlist_first_nvpair(nvl); + if (nvp == NULL) + goto continue_parent; continue; } else { size += nvpair_size(nvp); } while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) { +continue_parent: nvp = nvlist_get_nvpair_parent(nvl); if (nvp == NULL) goto out; @@ -533,6 +536,8 @@ nvl = nvpair_get_nvlist(nvp); nvp = nvlist_first_nvpair(nvl); ptr = nvlist_pack_header(nvl, ptr, &left); + if (nvp == NULL) + goto continue_parent; continue; #ifndef _KERNEL case NV_TYPE_DESCRIPTOR: @@ -550,6 +555,7 @@ return (NULL); } while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) { +continue_parent: nvp = nvlist_get_nvpair_parent(nvl); if (nvp == NULL) goto out;