From nobody Fri Jan 05 00:23:05 2024 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 4T5kgt0DdWz55fGN; Fri, 5 Jan 2024 00:23:06 +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 4T5kgs4n0Dz4dXv; Fri, 5 Jan 2024 00:23:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704414185; 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=p9ZByZXH2UMwFpJBq4MIJbyowEiHJeK888Z7nlOrtWc=; b=fvK20fsoI2u436QhtWIk6L9peqIUHia6/u3SxU+rUctVbpPqyKdWBV4ZKbxg4+CDqzOQQ3 vc4G0KZ8hZWcIepzHnP2hn1D1can29qkn+ko0gj3EaSDDIl9lyzV8OnVcvd16RlsSkTyiK /N0TY3SUuIPYv5HZ81wl+3dH3T5HC9CygNLH+b5A9/1wZEMx13HH+uyPj1al/aSQpCe0xK QTGTyrThvy5XRKqzYs92lWgyIlbQ14OxrIe04AfhCM58s2P1QnbicooegMSVQ81JesQxoL QaND6svii4Kh1eJdO8DXtHtu8BuOHYLMSdsH362lZkbZIsQW91Xrj9TvVJY5RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704414185; 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=p9ZByZXH2UMwFpJBq4MIJbyowEiHJeK888Z7nlOrtWc=; b=VhTWWlQqVQRA3DpxOCBq0YBjNvIEhAB17Mnb3l7RLp/VVal4yWGa8Bja+m/fQUr57Lrwhl 374zn6pGJRfPbE76n2jonwIHFaAyFIadeIq/IuJXYJCY/T+mUULANYUAIoE7kGQdYjZSYU chbefmECS8FW/DLJpxe8+4oE6fdnic/Gp2D9tHxQ51V/8+VUvLEtocREr8AbdSoH6Vouj/ 8qm2BT4ZdXDgHV7E7Lozt+0PonNUVkmnZkKHOmYm/LETjRHzqa2wQhYkBErThD+K26HRiY RTtRi6VDDy1jJTw2gzYTXx5DXYpJcYYMtNTnGJqRW4jHE25UjKjgOJRFGn8Xlg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704414185; a=rsa-sha256; cv=none; b=EIB5DTlTcNO8b9LuQgo1OXLgDYWQy3ReVzzeWezkdRiyObetRsDHaypUZJAoluSf/PGWok KG3kZyHbAFANBKnqwCA3JCBVD40wXqxpC2iYbTnMM8OH8SN3u6jl+inXFehAWnkU9FH6gU u08GcrfyzdnLQjWhB66hAOi+0prkSNowrG02cKvTvxoHc8LcjRI6iIHQkdVogGDIgz4be7 LrZCsAQVtaPmU4xIvLZKezOfyM5XrslMg1zqB+2mzwg5jI/8fV5TZqS48vwE7RFowLC5Zq SuQ6mI/drcEiDNs+PpVAIqdB+LuSQmYMM/WgpQ+VkZ9D41jh7Rffb+ZJ5KbYlA== 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 4T5kgs3ml9zbp7; Fri, 5 Jan 2024 00:23:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4050N51A025257; Fri, 5 Jan 2024 00:23:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4050N5oi025254; Fri, 5 Jan 2024 00:23:05 GMT (envelope-from git) Date: Fri, 5 Jan 2024 00:23:05 GMT Message-Id: <202401050023.4050N5oi025254@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 70f7bf34e3b4 - stable/13 - bsdinstall: Handle errors from geom_gettree. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 70f7bf34e3b4d0934c8c38ff49852eb6be343ac5 Auto-Submitted: auto-generated The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=70f7bf34e3b4d0934c8c38ff49852eb6be343ac5 commit 70f7bf34e3b4d0934c8c38ff49852eb6be343ac5 Author: John Baldwin AuthorDate: 2023-06-28 18:11:00 +0000 Commit: John Baldwin CommitDate: 2024-01-04 23:42:26 +0000 bsdinstall: Handle errors from geom_gettree. geom_gettree probably never fails, and if it does there isn't much of a fallback other than aborting partitioning. However, a few places were checking the return value and not doing anything with it triggering a unused-but-set-variable warning. Checking the errors resolves the warning. While here, check for errors in other places that weren't checking for them at all, remove a spurious double call (the second call overwrote the mesh structure leaking all the pointers from the first), and close a few resource leaks on error paths. Reviewed by: imp, emaste Differential Revision: https://reviews.freebsd.org/D40779 (cherry picked from commit 23099099196548550461ba427dcf09dcfb01878d) --- usr.sbin/bsdinstall/partedit/part_wizard.c | 40 +++++++++++++++++++----------- usr.sbin/bsdinstall/partedit/partedit.c | 22 ++++++++-------- usr.sbin/bsdinstall/partedit/scripted.c | 34 +++++++++++++++++-------- 3 files changed, 62 insertions(+), 34 deletions(-) diff --git a/usr.sbin/bsdinstall/partedit/part_wizard.c b/usr.sbin/bsdinstall/partedit/part_wizard.c index 2380e4d1f1b8..db689fd223d7 100644 --- a/usr.sbin/bsdinstall/partedit/part_wizard.c +++ b/usr.sbin/bsdinstall/partedit/part_wizard.c @@ -58,31 +58,37 @@ part_wizard(const char *fsreq) startwizard: error = geom_gettree(&mesh); + if (error != 0) + return (1); dlg_put_backtitle(); - error = geom_gettree(&mesh); disk = boot_disk_select(&mesh); - if (disk == NULL) + if (disk == NULL) { + geom_deletetree(&mesh); return (1); + } dlg_clear(); dlg_put_backtitle(); schemeroot = wizard_partition(&mesh, disk); free(disk); + geom_deletetree(&mesh); if (schemeroot == NULL) return (1); - geom_deletetree(&mesh); dlg_clear(); dlg_put_backtitle(); error = geom_gettree(&mesh); + if (error != 0) { + free(schemeroot); + return (1); + } error = wizard_makeparts(&mesh, schemeroot, fstype, 1); - if (error) - goto startwizard; free(schemeroot); - geom_deletetree(&mesh); + if (error) + goto startwizard; return (0); } @@ -280,11 +286,13 @@ query: if (strcmp(scheme, "MBR") == 0) { struct gmesh submesh; - geom_gettree(&submesh); - gpart_create(provider_for_name(&submesh, disk), - "freebsd", NULL, NULL, &retval, - choice /* Non-interactive for "Entire Disk" */); - geom_deletetree(&submesh); + + if (geom_gettree(&submesh) == 0) { + gpart_create(provider_for_name(&submesh, disk), + "freebsd", NULL, NULL, &retval, + choice /* Non-interactive for "Entire Disk" */); + geom_deletetree(&submesh); + } } else { retval = strdup(disk); } @@ -304,7 +312,7 @@ wizard_makeparts(struct gmesh *mesh, const char *disk, const char *fstype, struct gmesh submesh; char swapsizestr[10], rootsizestr[10]; intmax_t swapsize, available; - int retval; + int error, retval; if (strcmp(fstype, "zfs") == 0) { fsname = fsnames[1]; @@ -350,12 +358,16 @@ wizard_makeparts(struct gmesh *mesh, const char *disk, const char *fstype, humanize_number(rootsizestr, 7, available - swapsize - 1024*1024, "B", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); - geom_gettree(&submesh); + error = geom_gettree(&submesh); + if (error != 0) + return (error); pp = provider_for_name(&submesh, disk); gpart_create(pp, fsname, rootsizestr, "/", NULL, 0); geom_deletetree(&submesh); - geom_gettree(&submesh); + error = geom_gettree(&submesh); + if (error != 0) + return (error); pp = provider_for_name(&submesh, disk); gpart_create(pp, "freebsd-swap", swapsizestr, NULL, NULL, 0); geom_deletetree(&submesh); diff --git a/usr.sbin/bsdinstall/partedit/partedit.c b/usr.sbin/bsdinstall/partedit/partedit.c index 2ae71338d099..0f341cbaba12 100644 --- a/usr.sbin/bsdinstall/partedit/partedit.c +++ b/usr.sbin/bsdinstall/partedit/partedit.c @@ -60,9 +60,10 @@ sigint_handler(int sig) struct gmesh mesh; /* Revert all changes and exit dialog-mode cleanly on SIGINT */ - geom_gettree(&mesh); - gpart_revert_all(&mesh); - geom_deletetree(&mesh); + if (geom_gettree(&mesh) == 0) { + gpart_revert_all(&mesh); + geom_deletetree(&mesh); + } end_dialog(); @@ -209,16 +210,17 @@ main(int argc, const char **argv) if (prompt == NULL) { error = geom_gettree(&mesh); - if (validate_setup()) { - error = apply_changes(&mesh); - } else { - gpart_revert_all(&mesh); - error = -1; + if (error != 0) { + if (validate_setup()) { + error = apply_changes(&mesh); + } else { + gpart_revert_all(&mesh); + error = -1; + } + geom_deletetree(&mesh); } } - geom_deletetree(&mesh); - free(items); end_dialog(); return (error); diff --git a/usr.sbin/bsdinstall/partedit/scripted.c b/usr.sbin/bsdinstall/partedit/scripted.c index 69fba8f2cfa8..fdfdc2d10014 100644 --- a/usr.sbin/bsdinstall/partedit/scripted.c +++ b/usr.sbin/bsdinstall/partedit/scripted.c @@ -75,6 +75,8 @@ part_config(char *disk, const char *scheme, char *config) scheme = default_scheme(); error = geom_gettree(&mesh); + if (error != 0) + return (-1); if (provider_for_name(&mesh, disk) == NULL) { fprintf(stderr, "GEOM provider %s not found\n", disk); geom_deletetree(&mesh); @@ -96,16 +98,22 @@ part_config(char *disk, const char *scheme, char *config) if (strcmp(scheme, "MBR") == 0) { struct gmesh submesh; - geom_gettree(&submesh); - gpart_create(provider_for_name(&submesh, disk), - "freebsd", NULL, NULL, &disk, 0); - geom_deletetree(&submesh); + + if (geom_gettree(&submesh) == 0) { + gpart_create(provider_for_name(&submesh, disk), + "freebsd", NULL, NULL, &disk, 0); + geom_deletetree(&submesh); + } } else { - disk= strdup(disk); + disk = strdup(disk); } geom_deletetree(&mesh); error = geom_gettree(&mesh); + if (error != 0) { + free(disk); + return (-1); + } /* Create partitions */ if (config == NULL) { @@ -132,6 +140,10 @@ part_config(char *disk, const char *scheme, char *config) NULL, 0); geom_deletetree(&mesh); error = geom_gettree(&mesh); + if (error != 0) { + free(disk); + return (-1); + } size = type = mount = NULL; } @@ -142,8 +154,8 @@ finished: return (0); } -static -int parse_disk_config(char *input) +static int +parse_disk_config(char *input) { char *ap; char *disk = NULL, *scheme = NULL, *partconfig = NULL; @@ -183,9 +195,11 @@ int parse_disk_config(char *input) if (disk == NULL || strcmp(disk, "DEFAULT") == 0) { struct gmesh mesh; - geom_gettree(&mesh); - disk = boot_disk_select(&mesh); - geom_deletetree(&mesh); + + if (geom_gettree(&mesh) == 0) { + disk = boot_disk_select(&mesh); + geom_deletetree(&mesh); + } } return (part_config(disk, scheme, partconfig));