From 3d07176ffafb822442f2ede6de26a00e9a25aa85 Mon Sep 17 00:00:00 2001 From: Hao Wang Date: Sat, 8 Aug 2020 16:19:58 +0800 Subject: [PATCH] qemu: doCoreDump: Fix return value not expect as result In case qemuDumpToFd() returns zero followed by a VIR_CLOSE(fd) fail, we'd jump to the "cleanup" label with "ret=0", potentially resulting in an unexpected success return value. Signed-off-by: Hao Wang Reviewed-by: Erik Skultety --- src/qemu/qemu_driver.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8008da6d16..1b2ff1b3da 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3796,6 +3796,7 @@ doCoreDump(virQEMUDriverPtr driver, { int fd = -1; int ret = -1; + int rc = -1; virFileWrapperFdPtr wrapperFd = NULL; int directFlag = 0; unsigned int flags = VIR_FILE_WRAPPER_NON_BLOCKING; @@ -3843,8 +3844,8 @@ doCoreDump(virQEMUDriverPtr driver, if (STREQ(memory_dump_format, "elf")) memory_dump_format = NULL; - ret = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP, - memory_dump_format); + rc = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP, + memory_dump_format); } else { if (dumpformat != VIR_DOMAIN_CORE_DUMP_FORMAT_RAW) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", @@ -3856,11 +3857,11 @@ doCoreDump(virQEMUDriverPtr driver, if (!qemuMigrationSrcIsAllowed(driver, vm, false, 0)) goto cleanup; - ret = qemuMigrationSrcToFile(driver, vm, fd, compressor, - QEMU_ASYNC_JOB_DUMP); + rc = qemuMigrationSrcToFile(driver, vm, fd, compressor, + QEMU_ASYNC_JOB_DUMP); } - if (ret < 0) + if (rc < 0) goto cleanup; if (VIR_CLOSE(fd) < 0) {