github-advanced-security[bot] commented on code in PR #14926:
URL: https://github.com/apache/cloudstack/pull/14926#discussion_r4743235291
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertDiskOnlyVMSnapshotCommandWrapper.java:
##########
@@ -117,6 +114,79 @@
return new RevertDiskOnlyVmSnapshotAnswer(cmd, volumeObjectTos);
}
+ /**
+ * Brings a running VM back to the memory snapshot: the domain is stopped
and restored from the memory image, with its disks pointed at the new deltas.
+ */
+ protected void restoreMemoryStateIfNeeded(RevertDiskOnlyVmSnapshotCommand
cmd, LibvirtComputingResource resource, Map<SnapshotObjectTO, String>
snapshotToNewDeltaPath,
+ SnapshotObjectTO rootVolumeSnapshot, KVMStoragePoolManager
storagePoolMgr) throws IOException, LibvirtException {
+ if (StringUtils.isBlank(cmd.getMemorySnapshotPath())) {
+ return;
+ }
+
+ KVMStoragePool rootPool =
resource.getLibvirtUtilitiesHelper().getPrimaryPoolFromDataTo(rootVolumeSnapshot,
storagePoolMgr);
+ String memoryDevicePath =
storagePoolMgr.activateVmSnapshotMemoryFile(rootPool,
cmd.getMemorySnapshotPath());
+ try {
+ String domainXml = readSavedImageXml(memoryDevicePath);
+ for (Map.Entry<SnapshotObjectTO, String> snapshotAndNewDelta :
snapshotToNewDeltaPath.entrySet()) {
+ KVMStoragePool pool =
resource.getLibvirtUtilitiesHelper().getPrimaryPoolFromDataTo(snapshotAndNewDelta.getKey(),
storagePoolMgr);
+ domainXml = replaceDiskPath(domainXml,
pool.getLocalPathFor(snapshotAndNewDelta.getKey().getPath()),
pool.getLocalPathFor(snapshotAndNewDelta.getValue()));
+ }
+ Path domainXmlFile = Files.createTempFile("vm-snapshot-restore-",
".xml");
Review Comment:
## SonarCloud / Temporary files should not be created in publicly writable
directories
<!--SONAR_ISSUE_KEY:AaItl1zRh2r7PbCfI5Xe-->Make sure publicly writable
directories are used safely here. <p>See more on <a
href="https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaItl1zRh2r7PbCfI5Xe&open=AaItl1zRh2r7PbCfI5Xe&pullRequest=14926">SonarQube
Cloud</a></p>
[Show more
details](https://github.com/apache/cloudstack/security/code-scanning/238)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]