[libvirt] [PATCH v2 2/2] esx: Fix SetAutoStart invalid pointer free

Marcos Paulo de Souza marcos.souza.org at gmail.com
Wed Aug 1 16:09:34 UTC 2018


esxVI_AutoStartPowerInfo_Free, which is called from
esxVI_HostAutoStartManagerConfig_Free, will always call VIR_FREE to free
memory from {start,stop}Action, leading to a invalid pointer.

With this patch applied, ESX can set autostart successfully to all it's
domains.

Signed-off-by: Marcos Paulo de Souza <marcos.souza.org at gmail.com>
---

 Changes from v1:
 * Stop calling VIR_ALLOC_N and strcpy, and use VIR_STRNDUP instead

 src/esx/esx_driver.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 3835e4cb3c..dc07cf8770 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -3394,9 +3394,15 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart)
     newPowerInfo->startOrder->value = -1; /* no specific start order */
     newPowerInfo->startDelay->value = -1; /* use system default */
     newPowerInfo->waitForHeartbeat = esxVI_AutoStartWaitHeartbeatSetting_SystemDefault;
-    newPowerInfo->startAction = autostart ? (char *)"powerOn" : (char *)"none";
     newPowerInfo->stopDelay->value = -1; /* use system default */
-    newPowerInfo->stopAction = (char *)"none";
+
+    /* startAction and stopAction will be freed by esxVI_HostAutoStartManagerConfig_Free */
+    if (VIR_STRNDUP(newPowerInfo->startAction, autostart ? "powerOn" : "none",
+                    autostart ? 7 : 4) < 1)
+        goto cleanup;
+
+    if (VIR_STRNDUP(newPowerInfo->stopAction, "none", 4) < 1)
+        goto cleanup;
 
     if (esxVI_AutoStartPowerInfo_AppendToList(&spec->powerInfo,
                                               newPowerInfo) < 0) {
-- 
2.17.1




More information about the libvir-list mailing list