[PATCH] qemuDomainDefPostParse: Fail if unable to fill machine type

Michal Privoznik posted 1 patch 4 years ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/b4ea16268ebd3109762c41533b0ad2ec2bbff084.1587040413.git.mprivozn@redhat.com
src/qemu/qemu_domain.c | 8 ++++++++
1 file changed, 8 insertions(+)
[PATCH] qemuDomainDefPostParse: Fail if unable to fill machine type
Posted by Michal Privoznik 4 years ago
Previously, we used virCapabilitiesDomainDataLookup() to fill
machine type in post parse callback if none was provided in the
domain XML. If machine type couldn't be filled in an error was
reported. After 4a4132b4625 we've changed it to
virQEMUCapsGetPreferredMachine() which returns NULL, but we no
longer report an error and proceed with the post parse callbacks
processing. This may lead to a crash because the code later on
assumes def->os.machine is not NULL.

Fixes: 4a4132b4625

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_domain.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 91e234d644..98ffd23a71 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4973,6 +4973,14 @@ qemuDomainDefPostParse(virDomainDefPtr def,
     if (!def->os.machine) {
         const char *machine = virQEMUCapsGetPreferredMachine(qemuCaps,
                                                              def->virtType);
+        if (!machine) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("could not get preferred machine for %s type=%s"),
+                           def->emulator,
+                           virDomainVirtTypeToString(def->virtType));
+            return -1;
+        }
+
         def->os.machine = g_strdup(machine);
     }
 
-- 
2.25.3

Re: [PATCH] qemuDomainDefPostParse: Fail if unable to fill machine type
Posted by Pavel Mores 4 years ago
On Thu, Apr 16, 2020 at 02:33:33PM +0200, Michal Privoznik wrote:
> Previously, we used virCapabilitiesDomainDataLookup() to fill
> machine type in post parse callback if none was provided in the
> domain XML. If machine type couldn't be filled in an error was
> reported. After 4a4132b4625 we've changed it to
> virQEMUCapsGetPreferredMachine() which returns NULL, but we no
> longer report an error and proceed with the post parse callbacks
> processing. This may lead to a crash because the code later on
> assumes def->os.machine is not NULL.
> 
> Fixes: 4a4132b4625
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_domain.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 91e234d644..98ffd23a71 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -4973,6 +4973,14 @@ qemuDomainDefPostParse(virDomainDefPtr def,
>      if (!def->os.machine) {
>          const char *machine = virQEMUCapsGetPreferredMachine(qemuCaps,
>                                                               def->virtType);
> +        if (!machine) {
> +            virReportError(VIR_ERR_INVALID_ARG,
> +                           _("could not get preferred machine for %s type=%s"),
> +                           def->emulator,
> +                           virDomainVirtTypeToString(def->virtType));
> +            return -1;
> +        }
> +
>          def->os.machine = g_strdup(machine);
>      }
>  
> -- 
> 2.25.3
> 

Reviewed-by: Pavel Mores <pmores@redhat.com>