From nobody Fri Oct 28 21:01:07 2022 X-Original-To: dev-commits-src-all@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 4MzZhg2dNFz4frhr; Fri, 28 Oct 2022 21:01:07 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MzZhg28vSz3Cwb; Fri, 28 Oct 2022 21:01:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666990867; 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=La5Je1cpn0lDm4VrIZlbr4882kCiNnVf4BI2qk7ysbk=; b=mDJkqXOn5siiBGs3gFzPDkZrZ/7IaETBoAuwcc4zDEaHd6bdwSdFnvlWjvkWwHdy5CQIoe rzeFsFuck/nVeZU8i0ziVGVzLj3Kd1lcgeWPzSrHbyPvSGTLxgsMRCJuAeVqsHDHNsHBIS odf1aMrvuGGhdtEfjCTJB4qzZMrKUy+oHe7JNBNObHXEdFU3TyO6WnyIFh70iGnuWF8K4D COKmwTXyB+wHDKPVlOsgJAZdH9DXq0v8j1aSng2osocIeixgjEiY7eeGCnh8i0g6GLRfEJ pzDSjUxMrs/KzTaoYPf5aE0IuWNVuoGD3uAmuN5GZ7MnRo9pGxOIh1zfM87M2w== 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 4MzZhg0wVyzsC8; Fri, 28 Oct 2022 21:01:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29SL17br018027; Fri, 28 Oct 2022 21:01:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29SL17pO018026; Fri, 28 Oct 2022 21:01:07 GMT (envelope-from git) Date: Fri, 28 Oct 2022 21:01:07 GMT Message-Id: <202210282101.29SL17pO018026@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: 752ba1004aa9 - main - makefs: Fix handling of inherited mountpoints List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 752ba1004aa94e76df826fa803050fa7dffbcc78 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666990867; 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=La5Je1cpn0lDm4VrIZlbr4882kCiNnVf4BI2qk7ysbk=; b=Rtp4cFyX1thMwdjxJzllHXj4cjDXfvhkydmW88GVT8ZXmhk6OPNngjVuFnSBtENdgNYh7A QL4Iwe8Hdsqesb3owzOpJCc8nIUF74/LlViv80/oWiCsoUoHNXvM62cIqjrYf7W9q4PpHB gd9/QiyhMWNzyO6542ChVn2be7JnPpgHizTFFhxx32MjJdWBr98GkJCGZaAi6XI+XQvwho A6PgEua2yKODC3UCiPJRBM6F8bzJ/QDMkKLHlvcCQdSDEaZkwuMW9sb2c6xRirDvasr4gB 6BSFDxZi3anQ/x1VIt4jRUubDg0rPgNuHraZcWqihySJYW8W645mtuyPsrXBDw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666990867; a=rsa-sha256; cv=none; b=f5XB4JM+FgRDLYfXViWqDxpnfzx/+NuQOiusxOzUNhENlR5SsvEqhxs9eJrGddbPWlep73 sULhC0xrdHN2WfuAchHkWp/9W0mqY85izZaIqjrZxxu6dqYZi3k6cbDqVRQkXlGYThfpZ9 duZgTYxJpY5dyD/Jw3xCkWXn0ZPcQCb+n6ImQTdPOXQHE0KkBJQ1IFN6J4Lxcid0V0rNDb G/at9jYSRlJsfI+q2FV49MYzKHs/SRrIwZqyJsGKy7fVjb3pYmmv12TlmofsW4vylaAbZw 8tQ1+d8fvgkl82qejHMzyMh3omxmteBLBOvTHCZg1stitcWr8p2QjL+HpQrfBA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=752ba1004aa94e76df826fa803050fa7dffbcc78 commit 752ba1004aa94e76df826fa803050fa7dffbcc78 Author: Mark Johnston AuthorDate: 2022-10-28 20:51:00 +0000 Commit: Mark Johnston CommitDate: 2022-10-28 21:00:22 +0000 makefs: Fix handling of inherited mountpoints Commit d7eec79b7021 overlooked the fact that nvlist_find(DATA_TYPE_STRING) does not provide a nul-terminated string. Fix the leak a different way. Fixes: d7eec79b7021 ("makefs: Plug a memory leak") --- usr.sbin/makefs/zfs/dsl.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/usr.sbin/makefs/zfs/dsl.c b/usr.sbin/makefs/zfs/dsl.c index 52cb2fa22589..9c0e428fe67e 100644 --- a/usr.sbin/makefs/zfs/dsl.c +++ b/usr.sbin/makefs/zfs/dsl.c @@ -75,8 +75,10 @@ nvlist_find_string(nvlist_t *nvl, const char *key, char **retp) int error, len; error = nvlist_find(nvl, key, DATA_TYPE_STRING, NULL, &str, &len); - if (error == 0) - *retp = str; + if (error == 0) { + *retp = ecalloc(1, len + 1); + memcpy(*retp, str, len); + } return (error); } @@ -97,16 +99,11 @@ char * dsl_dir_get_mountpoint(zfs_opt_t *zfs, zfs_dsl_dir_t *dir) { zfs_dsl_dir_t *pdir; - char *mountpoint, *origmountpoint; + char *mountpoint; if (nvlist_find_string(dir->propsnv, "mountpoint", &mountpoint) == 0) { if (strcmp(mountpoint, "none") == 0) return (NULL); - - /* - * nvlist_find_string() does not make a copy. - */ - mountpoint = estrdup(mountpoint); } else { /* * If we don't have a mountpoint, it's inherited from one of our @@ -114,14 +111,18 @@ dsl_dir_get_mountpoint(zfs_opt_t *zfs, zfs_dsl_dir_t *dir) * up our mountpoint along the way. The mountpoint property is * always set for the root dataset. */ - for (pdir = dir->parent, mountpoint = estrdup(dir->name);;) { + for (pdir = dir->parent, mountpoint = estrdup(dir->name);; + pdir = pdir->parent) { + char *origmountpoint, *tmp; + origmountpoint = mountpoint; if (nvlist_find_string(pdir->propsnv, "mountpoint", - &mountpoint) == 0) { - easprintf(&mountpoint, "%s%s%s", mountpoint, - mountpoint[strlen(mountpoint) - 1] == '/' ? - "" : "/", origmountpoint); + &tmp) == 0) { + easprintf(&mountpoint, "%s%s%s", tmp, + tmp[strlen(tmp) - 1] == '/' ? "" : "/", + origmountpoint); + free(tmp); free(origmountpoint); break; } @@ -129,7 +130,6 @@ dsl_dir_get_mountpoint(zfs_opt_t *zfs, zfs_dsl_dir_t *dir) easprintf(&mountpoint, "%s/%s", pdir->name, origmountpoint); free(origmountpoint); - pdir = pdir->parent; } } assert(mountpoint[0] == '/');