[libvirt] [PATCH v3 01/10] storage: Don't allow encryption secretPath to be NULL

John Ferlan jferlan at redhat.com
Wed Jun 20 23:01:10 UTC 2018


Allowing a NULL @secretPath for virStorageBackendCreateQemuImgCmdFromVol
would result in a generated command line with a dangling "file=" output.
So let's make sure the @secretPath exists before processing.

This means we should pass a dummy path from the storage test.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/storage/storage_util.c     | 5 +++++
 tests/storagevolxml2argvtest.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 87f2115869..88427cecb4 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -1233,6 +1233,11 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
 
     if (info.format == VIR_STORAGE_FILE_RAW && vol->target.encryption &&
         vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
+        if (!info.secretPath) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("path to secret data file is required"));
+            goto error;
+        }
         if (virAsprintf(&info.secretAlias, "%s_encrypt0", vol->name) < 0)
             goto error;
         if (storageBackendCreateQemuImgSecretObject(cmd, info.secretPath,
diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c
index 0265a0ffe2..4286c50c6e 100644
--- a/tests/storagevolxml2argvtest.c
+++ b/tests/storagevolxml2argvtest.c
@@ -82,7 +82,7 @@ testCompareXMLToArgvFiles(bool shouldFail,
     cmd = virStorageBackendCreateQemuImgCmdFromVol(obj, vol,
                                                    inputvol, flags,
                                                    create_tool,
-                                                   NULL);
+                                                   "/path/to/secretFile");
     if (!cmd) {
         if (shouldFail) {
             virResetLastError();
-- 
2.14.4




More information about the libvir-list mailing list