From nobody Wed Sep 10 16:00:51 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cMQQX0TtQz66Wft; Wed, 10 Sep 2025 16:00:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cMQQW74F2z3KMF; Wed, 10 Sep 2025 16:00:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757520052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iUz6ez7mlv84iF20/UgRmjv2z3VZRHIMojFtjaUiI8g=; b=OnAVkC8kRZRMirOFFyj/69sJQCtM7PTA9NyZHDVVsS0KBgMUzNBM1ab7EiojJg4PAKZx1A 2lDu5becz9YkyScYeWtazng1wF3xOS5ztnNAkI4nf6D2gXHBauOu8TrvjiOZZTuVWXbYKe wProF9EnqS7OZrgJaVg0Yx7EmM/C53sgrwjJDEklkS3mgJ85VIqziN5+QYQcn9NA+IUzsO 0HCVyX/03N76/uwBQvktQjZPzA4V++OZyVBEkNmpfg/SVhHh1pz5AYP3JJN0lruj2sUvYr m9X0lRGft3hGISE+zgJjgqPfv+XltPmeqyetKEMYlExvgXF2LJ9qT9wtRRCRmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757520052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iUz6ez7mlv84iF20/UgRmjv2z3VZRHIMojFtjaUiI8g=; b=hjDbPq1XbZucABrvj14nVZV554MNLSL78iXWPu6GAsZfU4MdybDaLmm16XWbrmML/wDx+Z lXN0qx7lY/sB9v7+6yvHE47JwlZM/kPYIlcxf5E4Swl2zjCSdWP1sZ4jKn3NodR0KoUxUs 3pJPzFKJge5Z1Rb4wPcQNNg3kgE4nMPfybulX81F9XyXy5QcCfRQOwsWcOBVaL8h4KlK4P BZ6+uvgk096wvRMePQRGvKzlrRthrxBIpWoKRXItowYrTQdAHPpBDpHDQo6MZSTkniuYzk RERYiG66+3o1VohaVilpiiRc3wylQd22du7A2vONkyXmDs++aE1EBqFAdz6Y9w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1757520052; a=rsa-sha256; cv=none; b=cYGKvv9sGP5SxRF686ODiTXoxkP2vOy8NObRLAIVrVqgs5b0+2MgWX2kYCpXke5jB4yedc KQLvPipA3JsKOemaFIV4Q5kgyXEX3oeZ2uIayeqsPewDOFULHRg+yf4xA+c0mBnpK6pvno Ct8ytXgA9Bi3+kssnO/AhCKp8YUZPD9sGz/2oqnYrIdm+hUle0EM2Sf/nUscPjcubtzHsN iwmv48puP4NHY9g7s8zxdWbkWYvMj5U0dEa6VZDRnMJwxcdHlJzTa0mFBJneehJVTCPbDn 7c6Duyvf31sKwgG9SrCKofESGrj1hM9+yzveGeQnsywVrpDHOIxxvjNh2bp/+Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cMQQW6TcQzCc7; Wed, 10 Sep 2025 16:00:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 58AG0ptn058412; Wed, 10 Sep 2025 16:00:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58AG0phv058409; Wed, 10 Sep 2025 16:00:51 GMT (envelope-from git) Date: Wed, 10 Sep 2025 16:00:51 GMT Message-Id: <202509101600.58AG0phv058409@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 0b68e3ce6e0e - main - libnv: Fix handling of nvlist_dump() and nvlist_send() for child nvlists List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0b68e3ce6e0e437fa480b25a0ef706ee08562257 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=0b68e3ce6e0e437fa480b25a0ef706ee08562257 commit 0b68e3ce6e0e437fa480b25a0ef706ee08562257 Author: Mark Johnston AuthorDate: 2025-09-10 14:33:35 +0000 Commit: Mark Johnston CommitDate: 2025-09-10 16:00:13 +0000 libnv: Fix handling of nvlist_dump() and nvlist_send() for child nvlists Suppose an nvlist nvl belongs to a parent nvlist or nvlist array. In this case, nvl contains a pointer to its container. This trips up nvlist_send(nvl) and nvlist_dump(nvl), which intuitively should only operate on nvl and its nvpairs. In particular, both of these functions will traverse to nvl's parent and start sending/dumping the parent's nvpairs, which results in assertion failures or nonsensical output, respectively. Reviewed by: oshogbo MFC after: 2 weeks Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D52360 --- sys/contrib/libnv/nvlist.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/contrib/libnv/nvlist.c b/sys/contrib/libnv/nvlist.c index 41edc72322c3..73226ee51a78 100644 --- a/sys/contrib/libnv/nvlist.c +++ b/sys/contrib/libnv/nvlist.c @@ -478,7 +478,7 @@ nvlist_dump_error_check(const nvlist_t *nvl, int fd, int level) void nvlist_dump(const nvlist_t *nvl, int fd) { - const nvlist_t *tmpnvl; + const nvlist_t *tmpnvl, *top; nvpair_t *nvp, *tmpnvp; void *cookie; int level; @@ -487,6 +487,7 @@ nvlist_dump(const nvlist_t *nvl, int fd) if (nvlist_dump_error_check(nvl, fd, level)) return; + top = nvl; nvp = nvlist_first_nvpair(nvl); while (nvp != NULL) { dprintf(fd, "%*s%s (%s):", level * 4, "", nvpair_name(nvp), @@ -645,6 +646,8 @@ nvlist_dump(const nvlist_t *nvl, int fd) while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) { do { + if (nvl == top) + return; cookie = NULL; if (nvlist_in_array(nvl)) dprintf(fd, "%*s,\n", level * 4, ""); @@ -847,7 +850,7 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep) { unsigned char *buf, *ptr; size_t left, size; - const nvlist_t *tmpnvl; + const nvlist_t *tmpnvl, *top; nvpair_t *nvp, *tmpnvp; void *cookie; @@ -868,6 +871,7 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep) ptr = nvlist_pack_header(nvl, ptr, &left); + top = nvl; nvp = nvlist_first_nvpair(nvl); while (nvp != NULL) { NVPAIR_ASSERT(nvp); @@ -958,6 +962,8 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep) goto fail; while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) { do { + if (nvl == top) + goto out; cookie = NULL; if (nvlist_in_array(nvl)) { ptr = nvpair_pack_nvlist_array_next(ptr,