From nobody Wed Jun 28 18:11:15 2023 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 4QrqQW3Jf8z4kW2Z; Wed, 28 Jun 2023 18:11:15 +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 4QrqQW2sDhz46m9; Wed, 28 Jun 2023 18:11:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687975875; 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=K42crHyr/tiXqFJkAGBHe+s2YB/wySpmozBTftvk+Tg=; b=v7z/Ik7lYTVe0eCtX2vOH/+FiQKkOVhHcfnSAHvgHLWQE5cFigPFqNvXT6nwZvLjCILzv6 QxDsYL1TyV7daabv09JkXmWJtHhDcPLWImNXdiKsqcjgX0T1pPb3n7dVCc6wCt+Xy7tV6t I/P1Osk3wAa5kvW+q7ggHW2W4BNFAluOhe8J3nFYwqdzwSIsmejvhjrpY+9VkoevYxn7Xz ZCLiANA1SbvLEsG1sykJsOYf+ynizf4ep8TsRDCfj56Jd5x4ub9EQlA6ZgQt5aQjGq5ngX ut94x282qm5RT+IuTePX6O3rVJ+pjPiHscfvJaGeZ//NIQp6YtPw80Kfy0GS/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687975875; 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=K42crHyr/tiXqFJkAGBHe+s2YB/wySpmozBTftvk+Tg=; b=Q9C7DMK21vnjjrcCUy1YOdCCXKoqlZkXoAzRzYMz2W6RG5HOclOA9y17K0wAtg91magzHk 9HHSaqbfb9fWi7HnVVYYOwgnMzvHykeviESxvb6ycFoyhvCFb+crxzElQ1pJohqCACPDiC 3QNRg/eCCVg0yYvgbYOCtB/lhMfLhUQtAnUeFq/waOM0TSrrHfW4DAGw+5hXchOdv+B+5D 8Q06B3BAkbLchMtCUvS5QT0rJf/rQ2BB//+oO+zAW/KeE3A7PB5vgWz8PFXRZNqm2CUIt3 6eHOLLSbVVW2MWioRO/teqwnwX3//0CxFfqntA3unhx86rm/sPST1Hj9QbXqDQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687975875; a=rsa-sha256; cv=none; b=tl8ELQpiIQ8n+4aViu1KvJPMjeiK/dJM205V7bSiVvqYjOV8P0ryNBvu9Lg8Sz54ZtQTB1 XMhkh3fRasOUVwBsoFlPYPbS3eocSI57+/hULynd9BVmxwlreA2Wvk4/XC9MAumg73jyWR xMpWks5VE4Sv4bvBtrLB+2xAZwsRFVAyaZG4tB+qrBT9HY9ggW0Jc2O9oE0wE6CYvdPI18 fMkKWzDA6a2Tgx11jnm1fl2TMYjAmcUteFRh5rAZiPo0VWy31gIo0cVFsbadLcZj+0LIzk VP4f/K9Z9jmWpNKmeqJT7df53a8Yi5JL9PDqRIxFOSav7KRBcK9WvEmseULccA== 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 4QrqQW1xTWzjyS; Wed, 28 Jun 2023 18:11:15 +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 35SIBFOm005773; Wed, 28 Jun 2023 18:11:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35SIBF3H005772; Wed, 28 Jun 2023 18:11:15 GMT (envelope-from git) Date: Wed, 28 Jun 2023 18:11:15 GMT Message-Id: <202306281811.35SIBF3H005772@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 230990991965 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 23099099196548550461ba427dcf09dcfb01878d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=23099099196548550461ba427dcf09dcfb01878d commit 23099099196548550461ba427dcf09dcfb01878d Author: John Baldwin AuthorDate: 2023-06-28 18:11:00 +0000 Commit: John Baldwin CommitDate: 2023-06-28 18:11:00 +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 --- 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 db78cea768aa..e7b513f3193a 100644 --- a/usr.sbin/bsdinstall/partedit/part_wizard.c +++ b/usr.sbin/bsdinstall/partedit/part_wizard.c @@ -65,31 +65,37 @@ part_wizard(const char *fsreq) startwizard: error = geom_gettree(&mesh); + if (error != 0) + return (1); bsddialog_backtitle(&conf, "FreeBSD Installer"); - error = geom_gettree(&mesh); disk = boot_disk_select(&mesh); - if (disk == NULL) + if (disk == NULL) { + geom_deletetree(&mesh); return (1); + } bsddialog_clearterminal(); bsddialog_backtitle(&conf, "FreeBSD Installer"); schemeroot = wizard_partition(&mesh, disk); free(disk); + geom_deletetree(&mesh); if (schemeroot == NULL) return (1); - geom_deletetree(&mesh); bsddialog_clearterminal(); bsddialog_backtitle(&conf, "FreeBSD Installer"); 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); } @@ -310,11 +316,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); } @@ -334,7 +342,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; struct bsddialog_conf conf; if (strcmp(fstype, "zfs") == 0) { @@ -381,12 +389,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 f26aa0085748..ece258b2c070 100644 --- a/usr.sbin/bsdinstall/partedit/partedit.c +++ b/usr.sbin/bsdinstall/partedit/partedit.c @@ -63,9 +63,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); + } bsddialog_end(); @@ -216,16 +217,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); bsddialog_end(); return (error); diff --git a/usr.sbin/bsdinstall/partedit/scripted.c b/usr.sbin/bsdinstall/partedit/scripted.c index 62c36724d7c5..2f79d643fd08 100644 --- a/usr.sbin/bsdinstall/partedit/scripted.c +++ b/usr.sbin/bsdinstall/partedit/scripted.c @@ -76,6 +76,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); @@ -97,16 +99,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) { @@ -133,6 +141,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; } @@ -143,8 +155,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; @@ -184,9 +196,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));