1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-20 11:11:24 +00:00

Prevent creation of an invalid nvlist

If an nvlist is set as a child of another nvlist with
nvlist_move_nvlist then fail the operation and set the parent
nvlist to the error state.

Differential Revision:		https://reviews.freebsd.org/D1880
Reviewers:			jfv
MFC after:			1 month
Sponsored by:			Sandvine Inc
This commit is contained in:
Ryan Stone 2015-03-01 00:22:38 +00:00
parent ed007c94ba
commit 19a4afb3e6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=279436
2 changed files with 39 additions and 0 deletions

View File

@ -1128,6 +1128,12 @@ nvpair_movev_nvlist(nvlist_t *value, const char *namefmt, va_list nameap)
return (NULL);
}
if (nvlist_error(value) != 0) {
errno = nvlist_error(value);
nvlist_destroy(value);
return (NULL);
}
nvp = nvpair_allocv(NV_TYPE_NVLIST, (uint64_t)(uintptr_t)value, 0,
namefmt, nameap);
if (nvp == NULL)

View File

@ -243,6 +243,22 @@ ATF_TEST_CASE_BODY(nvlist_add_nvlist__single_insert)
nvlist_destroy(nvl);
}
ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_nvlist__child_with_error);
ATF_TEST_CASE_BODY(nvlist_add_nvlist__child_with_error)
{
nvlist_t *nvl, *parent;
nvl = nvlist_create(0);
parent = nvlist_create(0);
nvlist_set_error(nvl, EBADF);
nvlist_add_nvlist(parent, "test", nvl);
ATF_REQUIRE_EQ(nvlist_error(parent), EBADF);
nvlist_destroy(nvl);
nvlist_destroy(parent);
}
ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_binary__single_insert);
ATF_TEST_CASE_BODY(nvlist_add_binary__single_insert)
{
@ -654,6 +670,21 @@ ATF_TEST_CASE_BODY(nvlist_move_nvlist__null_child)
nvlist_destroy(parent);
}
ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__child_with_error);
ATF_TEST_CASE_BODY(nvlist_move_nvlist__child_with_error)
{
nvlist_t *nvl, *parent;
nvl = nvlist_create(0);
parent = nvlist_create(0);
nvlist_set_error(nvl, EBADF);
nvlist_move_nvlist(parent, "test", nvl);
ATF_REQUIRE_EQ(nvlist_error(parent), EBADF);
nvlist_destroy(parent);
}
ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__single_insert);
ATF_TEST_CASE_BODY(nvlist_move_nvlist__single_insert)
{
@ -1177,6 +1208,7 @@ ATF_INIT_TEST_CASES(tp)
ATF_ADD_TEST_CASE(tp, nvlist_add_number__single_insert);
ATF_ADD_TEST_CASE(tp, nvlist_add_string__single_insert);
ATF_ADD_TEST_CASE(tp, nvlist_add_nvlist__single_insert);
ATF_ADD_TEST_CASE(tp, nvlist_add_nvlist__child_with_error);
ATF_ADD_TEST_CASE(tp, nvlist_add_binary__single_insert);
ATF_ADD_TEST_CASE(tp, nvlist_clone__empty_nvlist);
@ -1192,6 +1224,7 @@ ATF_INIT_TEST_CASES(tp)
ATF_ADD_TEST_CASE(tp, nvlist_move_string__single_insert);
ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__single_insert);
ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__null_child);
ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__child_with_error);
ATF_ADD_TEST_CASE(tp, nvlist_move_binary__single_insert);
ATF_ADD_TEST_CASE(tp, nvlist_take_bool__single_remove);