git: 70f7bf34e3b4 - stable/13 - bsdinstall: Handle errors from geom_gettree.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 05 Jan 2024 00:23:05 UTC
The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=70f7bf34e3b4d0934c8c38ff49852eb6be343ac5 commit 70f7bf34e3b4d0934c8c38ff49852eb6be343ac5 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2023-06-28 18:11:00 +0000 Commit: John Baldwin <jhb@FreeBSD.org> 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));