From owner-svn-src-all@FreeBSD.ORG Fri Jan 30 12:31:30 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7F8E4F4B; Fri, 30 Jan 2015 12:31:30 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6218522A; Fri, 30 Jan 2015 12:31:30 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t0UCVUh5006808; Fri, 30 Jan 2015 12:31:30 GMT (envelope-from pjd@FreeBSD.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t0UCVUIu006807; Fri, 30 Jan 2015 12:31:30 GMT (envelope-from pjd@FreeBSD.org) Message-Id: <201501301231.t0UCVUIu006807@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: pjd set sender to pjd@FreeBSD.org using -f From: Pawel Jakub Dawidek Date: Fri, 30 Jan 2015 12:31:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r277925 - head/lib/libnv X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jan 2015 12:31:30 -0000 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 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;