]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_tpm: Don't report uninitialized variable in error message
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 17 Jul 2025 08:46:53 +0000 (10:46 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 18 Jul 2025 06:27:36 +0000 (08:27 +0200)
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 <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_tpm.c

index cdbd6e3993b29f2dea7a13b199f9f8c6d1835183..5cb678df0eeed175821dddb7ab5d3f9a13366e38 100644 (file)
@@ -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))