mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-29 00:55:22 +00:00
conf: Fix crash with cleanup
There was a crash possible when both <boot dev... and <boot
order... were specified due to virDomainDefParseBootXML() erroring out
before setting *tmp (which was free'd in cleanup). As a fix, I
created this cleanup that uses one pointer for all the temporary
stored XPath strings and values, plus this pointer is correctly
initialized to NULL.
(cherry picked from commit 280b8c9e7c
)
This commit is contained in:
parent
95110e715d
commit
1fd7c2617e
@ -8180,8 +8180,7 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
|
|||||||
{
|
{
|
||||||
xmlNodePtr *nodes = NULL;
|
xmlNodePtr *nodes = NULL;
|
||||||
int i, n;
|
int i, n;
|
||||||
char *bootstr, *tmp;
|
char *tmp = NULL;
|
||||||
char *useserial = NULL;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
unsigned long deviceBoot, serialPorts;
|
unsigned long deviceBoot, serialPorts;
|
||||||
|
|
||||||
@ -8228,23 +8227,23 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
|
|||||||
def->os.bootDevs[0] = VIR_DOMAIN_BOOT_DISK;
|
def->os.bootDevs[0] = VIR_DOMAIN_BOOT_DISK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstr = virXPathString("string(./os/bootmenu[1]/@enable)", ctxt);
|
tmp = virXPathString("string(./os/bootmenu[1]/@enable)", ctxt);
|
||||||
if (bootstr) {
|
if (tmp) {
|
||||||
def->os.bootmenu = virDomainBootMenuTypeFromString(bootstr);
|
def->os.bootmenu = virDomainBootMenuTypeFromString(tmp);
|
||||||
if (def->os.bootmenu <= 0) {
|
if (def->os.bootmenu <= 0) {
|
||||||
/* In order not to break misconfigured machines, this
|
/* In order not to break misconfigured machines, this
|
||||||
* should not emit an error, but rather set the bootmenu
|
* should not emit an error, but rather set the bootmenu
|
||||||
* to disabled */
|
* to disabled */
|
||||||
VIR_WARN("disabling bootmenu due to unknown option '%s'",
|
VIR_WARN("disabling bootmenu due to unknown option '%s'",
|
||||||
bootstr);
|
tmp);
|
||||||
def->os.bootmenu = VIR_DOMAIN_BOOT_MENU_DISABLED;
|
def->os.bootmenu = VIR_DOMAIN_BOOT_MENU_DISABLED;
|
||||||
}
|
}
|
||||||
VIR_FREE(bootstr);
|
VIR_FREE(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
useserial = virXPathString("string(./os/bios[1]/@useserial)", ctxt);
|
tmp = virXPathString("string(./os/bios[1]/@useserial)", ctxt);
|
||||||
if (useserial) {
|
if (tmp) {
|
||||||
if (STREQ(useserial, "yes")) {
|
if (STREQ(tmp, "yes")) {
|
||||||
if (virXPathULong("count(./devices/serial)",
|
if (virXPathULong("count(./devices/serial)",
|
||||||
ctxt, &serialPorts) < 0) {
|
ctxt, &serialPorts) < 0) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
@ -8256,6 +8255,7 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
|
|||||||
} else {
|
} else {
|
||||||
def->os.bios.useserial = VIR_DOMAIN_BIOS_USESERIAL_NO;
|
def->os.bios.useserial = VIR_DOMAIN_BIOS_USESERIAL_NO;
|
||||||
}
|
}
|
||||||
|
VIR_FREE(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = virXPathString("string(./os/bios[1]/@rebootTimeout)", ctxt);
|
tmp = virXPathString("string(./os/bios[1]/@rebootTimeout)", ctxt);
|
||||||
@ -8277,7 +8277,6 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
VIR_FREE(useserial);
|
|
||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user