[libvirt] [PATCH] qemu: Avoid crashes in qemuDomainMachineIs*()

Daniel P. Berrange berrange at redhat.com
Tue Oct 10 14:49:49 UTC 2017

On Tue, Oct 10, 2017 at 04:21:02PM +0200, Andrea Bolognani wrote:
> Make sure pointers are non-NULL before dereferencing them, and
> add test suite coverage for the crashers doing so fixes.
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1379218

Hmm, I don't think that is a good fix for the problem seen there.

We're parsing the CLI argv from an existing QEMU process and
when looking at the disk we're checking if the machine type
refers to a pseries guest.

The problem is that either the user might not have given any
-machine arg, or the -drive arg might occur *before* the
-machine arg is parsed.

Simply making the qemuDomainMachineIs* safe against NULL will
avoid the crash, but the ARGV parsing is still going to be
semantically broken.

As a more general point, we've tended to assume that machine
is always non-NULL throughout the code, because we rely on
the XML parsing to fill in defaults if omitted by the user.

I think rather than trying to fix up the assumption about
machine being non-NULL, we should restructure the ARGV
parsing into we need a 2 pass process.

In the first pass only look for the -machine arg. If no
-machine arg is given, we should fill in the default machine
for that emulator.

In the second pass process the rest of the ARGV, whereupon
we have a valid assumption that machine is non-NULL.

|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

More information about the libvir-list mailing list