svn commit: r277925 - head/lib/libnv

Pawel Jakub Dawidek pjd at FreeBSD.org
Fri Jan 30 12:31:30 UTC 2015


Author: pjd
Date: Fri Jan 30 12:31:29 2015
New Revision: 277925
URL: https://svnweb.freebsd.org/changeset/base/277925

Log:
  Handle empty nvlists correctly.
  
  Submitted by:	Mariusz Zaborski <oshogbo at FreeBSD.org>

Modified:
  head/lib/libnv/nvlist.c

Modified: head/lib/libnv/nvlist.c
==============================================================================
--- head/lib/libnv/nvlist.c	Fri Jan 30 12:07:43 2015	(r277924)
+++ head/lib/libnv/nvlist.c	Fri Jan 30 12:31:29 2015	(r277925)
@@ -356,7 +356,8 @@ nvlist_dump_error_check(const nvlist_t *
 void
 nvlist_dump(const nvlist_t *nvl, int fd)
 {
-	nvpair_t *nvp;
+	const nvlist_t *tmpnvl;
+	nvpair_t *nvp, *tmpnvp;
 	int level;
 
 	level = 0;
@@ -386,13 +387,17 @@ nvlist_dump(const nvlist_t *nvl, int fd)
 			break;
 		case NV_TYPE_NVLIST:
 			dprintf(fd, "\n");
-			nvl = nvpair_get_nvlist(nvp);
-			if (nvlist_dump_error_check(nvl, fd, level + 1)) {
-				nvl = nvlist_get_parent(nvl, (void **)&nvp);
+			tmpnvl = nvpair_get_nvlist(nvp);
+			if (nvlist_dump_error_check(tmpnvl, fd, level + 1))
 				break;
+			tmpnvp = nvlist_first_nvpair(tmpnvl);
+			if (tmpnvp != NULL) {
+				nvl = tmpnvl;
+				nvp = tmpnvp;
+				level++;
+				continue;
 			}
-			level++;
-			continue;
+			break;
 		case NV_TYPE_DESCRIPTOR:
 			dprintf(fd, " %d\n", nvpair_get_descriptor(nvp));
 			break;
@@ -436,7 +441,8 @@ nvlist_fdump(const nvlist_t *nvl, FILE *
 size_t
 nvlist_size(const nvlist_t *nvl)
 {
-	const nvpair_t *nvp;
+	const nvlist_t *tmpnvl;
+	const nvpair_t *nvp, *tmpnvp;
 	size_t size;
 
 	NVLIST_ASSERT(nvl);
@@ -450,10 +456,14 @@ nvlist_size(const nvlist_t *nvl)
 		if (nvpair_type(nvp) == NV_TYPE_NVLIST) {
 			size += sizeof(struct nvlist_header);
 			size += nvpair_header_size() + 1;
-			nvl = nvpair_get_nvlist(nvp);
-			PJDLOG_ASSERT(nvl->nvl_error == 0);
-			nvp = nvlist_first_nvpair(nvl);
-			continue;
+			tmpnvl = nvpair_get_nvlist(nvp);
+			PJDLOG_ASSERT(tmpnvl->nvl_error == 0);
+			tmpnvp = nvlist_first_nvpair(tmpnvl);
+			if (tmpnvp != NULL) {
+				nvl = tmpnvl;
+				nvp = tmpnvp;
+				continue;
+			}
 		} else {
 			size += nvpair_size(nvp);
 		}
@@ -575,7 +585,8 @@ nvlist_xpack(const nvlist_t *nvl, int64_
 {
 	unsigned char *buf, *ptr;
 	size_t left, size;
-	nvpair_t *nvp;
+	const nvlist_t *tmpnvl;
+	nvpair_t *nvp, *tmpnvp;
 
 	NVLIST_ASSERT(nvl);
 
@@ -618,10 +629,18 @@ nvlist_xpack(const nvlist_t *nvl, int64_
 			ptr = nvpair_pack_string(nvp, ptr, &left);
 			break;
 		case NV_TYPE_NVLIST:
-			nvl = nvpair_get_nvlist(nvp);
-			nvp = nvlist_first_nvpair(nvl);
-			ptr = nvlist_pack_header(nvl, ptr, &left);
-			continue;
+			tmpnvl = nvpair_get_nvlist(nvp);
+			ptr = nvlist_pack_header(tmpnvl, ptr, &left);
+			if (ptr == NULL)
+				goto out;
+			tmpnvp = nvlist_first_nvpair(tmpnvl);
+			if (tmpnvp != NULL) {
+				nvl = tmpnvl;
+				nvp = tmpnvp;
+				continue;
+			}
+			ptr = nvpair_pack_nvlist_up(ptr, &left);
+			break;
 		case NV_TYPE_DESCRIPTOR:
 			ptr = nvpair_pack_descriptor(nvp, ptr, fdidxp, &left);
 			break;


More information about the svn-src-all mailing list