From 2d5ce69aa97d900c8d62d29f0a8c6a7a49788973 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Thu, 17 Jul 2025 10:46:53 +0200 Subject: [PATCH] qemu_tpm: Don't report uninitialized variable in error message MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Inside to qemu_tpm.c there are three functions that use the same pattern (qemuTPMEmulatorRunSetup(), qemuTPMEmulatorReconfigure() and qemuTPMEmulatorUpdateProfileName()): int exitstatus; ... if (virCommandRun(cmd, &exitstatus) < 0 || exitstatus != 0) { virReportError(..., exitstatus); return -1; } Problem with this pattern is that if virCommandRun() fails then exitstatus is left untouched and a garbage value is then passed to virReportError(). Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- src/qemu/qemu_tpm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index cdbd6e3993..5cb678df0e 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -473,7 +473,7 @@ qemuTPMEmulatorRunSetup(const virDomainTPMEmulatorDef *emulator, bool incomingMigration) { g_autoptr(virCommand) cmd = NULL; - int exitstatus; + int exitstatus = -1; char uuid[VIR_UUID_STRING_BUFLEN]; g_autofree char *vmid = NULL; g_autofree char *swtpm_setup = virTPMGetSwtpmSetup(); @@ -581,7 +581,7 @@ qemuTPMEmulatorReconfigure(const virDomainTPMEmulatorDef *emulator, const unsigned char *secretuuid) { g_autoptr(virCommand) cmd = NULL; - int exitstatus; + int exitstatus = -1; g_autofree char *activePcrBanksStr = NULL; g_autofree char *swtpm_setup = virTPMGetSwtpmSetup(); g_autofree char *tpm_state = qemuTPMGetSwtpmSetupStateArg(emulator->source_type, @@ -708,7 +708,7 @@ qemuTPMEmulatorUpdateProfileName(virDomainTPMEmulatorDef *emulator, g_autofree char *swtpm = NULL; virJSONValue *active_profile; const char *profile_name; - int exitstatus; + int exitstatus = -1; if (emulator->version != VIR_DOMAIN_TPM_VERSION_2_0 || !virTPMSwtpmCapsGet(VIR_TPM_SWTPM_FEATURE_CMDARG_PRINT_INFO)) -- 2.47.2