]> git.ipfire.org Git - thirdparty/libvirt.git/commit
conf: avoid NULL deref for pmsuspended domain state
authorEric Blake <eblake@redhat.com>
Thu, 24 Jan 2013 00:06:06 +0000 (17:06 -0700)
committerEric Blake <eblake@redhat.com>
Fri, 25 Jan 2013 16:37:44 +0000 (09:37 -0700)
commite0642059367436c27bc031df3b03ccdc1d818350
tree8f51dbf53581fb83ec80f2a4234bd096179ddf92
parentf0aa4935d3c711c18fc07bcad071bc6af832625a
conf: avoid NULL deref for pmsuspended domain state

While working with a pmsuspend vs. snapshot issue, I noticed that
the state file in /var/run/libvirt/qemu/dom.xml contained a rather
suspicious "(null)" string, which does not round-trip well through
a libvirtd restart.  Had I been on a platform other than glibc
where printf("%s",NULL) crashes instead of printing (null), we might
have noticed the problem much sooner.

And in fixing that problem, I also noticed that we had several
missing states, because we were #defining several *_LAST names
to a value _different_ than what they were already given as enums
in libvirt.h.  Yuck.  I got rid of default: labels in the case
statements, because they get in the way of gcc's -Wswitch helping
us ensure we cover all enum values.

* src/conf/domain_conf.c (virDomainStateReasonToString)
(virDomainStateReasonFromString): Fill in missing domain states;
rewrite case statement to let compiler enforce checking.
(VIR_DOMAIN_NOSTATE_LAST, VIR_DOMAIN_RUNNING_LAST)
(VIR_DOMAIN_BLOCKED_LAST, VIR_DOMAIN_PAUSED_LAST)
(VIR_DOMAIN_SHUTDOWN_LAST, VIR_DOMAIN_SHUTOFF_LAST)
(VIR_DOMAIN_CRASHED_LAST): Drop dead defines.
(VIR_DOMAIN_PMSUSPENDED_LAST): Drop dead define.
(virDomainPMSuspendedReason): Add missing enum function.
(virDomainRunningReason, virDomainPausedReason): Add missing enum
value.
* src/conf/domain_conf.h (virDomainPMSuspendedReason): Declare
missing functions.
* src/libvirt_private.syms (domain_conf.h): Export them.
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms