From 3989e1b74119805b19cd708b62a6ba0a0b30295f Mon Sep 17 00:00:00 2001 From: Eduard Shishkin Date: Tue, 17 Sep 2024 14:37:03 +0200 Subject: [PATCH] zipl/src: fix segfault on '--dry-run' for device-based dumps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a segfault when the option '--dry-run' is specified for device-based dumps (for which the bootmap file is created on a RAW device, not formatted with a file system). The actual status is that the option '--dry-run' for device-based dumps is not implemented. The implementation is evaluated as not trivial: In contrast with filesystem-based dumps, it is not possible to simply make do with rename/unlink of temporary created bootmap. The fixup returns error on any not file system based dumps being created with the option '--dry-run'. Signed-off-by: Eduard Shishkin Reviewed-by: Mikhail Zaslonko Signed-off-by: Jan Höppner --- zipl/src/bootmap.c | 34 +++++++++++----------------------- zipl/src/zipl.c | 5 +++++ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/zipl/src/bootmap.c b/zipl/src/bootmap.c index f4aec693..7d340156 100644 --- a/zipl/src/bootmap.c +++ b/zipl/src/bootmap.c @@ -1442,30 +1442,18 @@ static int prepare_build_program_table_device(struct job_data *job, if (bis->skip_prepare) /* skip the preparation work */ return 0; + if (dry_run) { + error_text("Option '--dry-run' is not implemented for this type of dump"); + return -1; + } /* Get full path of bootmap file */ - if (!dry_run) { - bis->filename = misc_strdup(job->data.dump.device); - if (!bis->filename) - return -1; - bis->fd = misc_open_exclusive(bis->filename); - if (bis->fd == -1) { - error_text("Could not open file '%s'", bis->filename); - return -1; - } - } else { - bis->filename = misc_make_path(job->target.bootmap_dir, - BOOTMAP_TEMPLATE_FILENAME); - if (!bis->filename) - return -1; - /* Create temporary bootmap file */ - bis->fd = mkstemp(bis->filename); - if (bis->fd == -1) { - error_reason(strerror(errno)); - error_text("Could not create file '%s':", - bis->filename); - return -1; - } - bis->tmp_filename_created = 1; + bis->filename = misc_strdup(job->data.dump.device); + if (!bis->filename) + return -1; + bis->fd = misc_open_exclusive(bis->filename); + if (bis->fd == -1) { + error_text("Could not open file '%s'", bis->filename); + return -1; } /* Retrieve target device information */ if (disk_get_info(bis->filename, &job->target, &bis->info)) diff --git a/zipl/src/zipl.c b/zipl/src/zipl.c index 2e0f1678..0f2345cd 100644 --- a/zipl/src/zipl.c +++ b/zipl/src/zipl.c @@ -181,6 +181,11 @@ main(int argc, char* argv[]) if (!job_dump_is_ngdump(job) && (disk_is_tape(job->data.dump.device) || !disk_type_is_scsi(&ext_type))) { + if (dry_run) { + error_text("Option '--dry-run' is not implemented for this type of dump"); + rc = -1; + break; + } rc = install_dump(job->data.dump.device, &job->target, job->data.dump.mem, job->data.dump.no_compress); break;