Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 1 Mar 2015 00:22:39 +0000 (UTC)
From:      Ryan Stone <rstone@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r279436 - in head/lib/libnv: . tests
Message-ID:  <201503010022.t210MdOr083768@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rstone
Date: Sun Mar  1 00:22:38 2015
New Revision: 279436
URL: https://svnweb.freebsd.org/changeset/base/279436

Log:
  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

Modified:
  head/lib/libnv/nvpair.c
  head/lib/libnv/tests/nv_tests.cc

Modified: head/lib/libnv/nvpair.c
==============================================================================
--- head/lib/libnv/nvpair.c	Sun Mar  1 00:22:31 2015	(r279435)
+++ head/lib/libnv/nvpair.c	Sun Mar  1 00:22:38 2015	(r279436)
@@ -1128,6 +1128,12 @@ nvpair_movev_nvlist(nvlist_t *value, con
 		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)

Modified: head/lib/libnv/tests/nv_tests.cc
==============================================================================
--- head/lib/libnv/tests/nv_tests.cc	Sun Mar  1 00:22:31 2015	(r279435)
+++ head/lib/libnv/tests/nv_tests.cc	Sun Mar  1 00:22:38 2015	(r279436)
@@ -243,6 +243,22 @@ ATF_TEST_CASE_BODY(nvlist_add_nvlist__si
 	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__n
 	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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201503010022.t210MdOr083768>