virt-v2v/0003-input-parse_vmx.ml-Rej...

41 lines
1.5 KiB
Diff

From 6f2536bd9fbc335d3fb460d8c3317664d0bd813a Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 19 Dec 2023 12:53:56 +0000
Subject: [PATCH] input/parse_vmx.ml: Reject VMDK files
Instead of the confusing warnings printed before, it now prints
an error indicating the incorrect input format:
$ virt-v2v -i vmx -it ssh ssh://root@xxx/vmfs/volumes/esx8.0-function/Auto-esx8.0-rhell9.3-efi-with-empty-cdrom/Auto-esx8.0-rhell9.3-efi-with-empty-cdrom.vmdk -ip /tmp/passwd -o null
virt-v2v: error: input file is a VMDK (disk image), but we are expecting a
VMX (VMware metadata)
Reported-by: Ming Xie
Fixes: https://issues.redhat.com/browse/RHEL-19564
---
input/parse_vmx.ml | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/input/parse_vmx.ml b/input/parse_vmx.ml
index 65d5a0ed..43d05bf3 100644
--- a/input/parse_vmx.ml
+++ b/input/parse_vmx.ml
@@ -274,6 +274,17 @@ let rec parse_file vmx_filename =
parse_string str
and parse_string str =
+ (* Reject VMDK files early, since in virt-v2v we have seen users try
+ * to pass a .vmdk file as a .vmx file. Luckily this is easy to
+ * do with the whole file as a string.
+ *)
+ if String.is_prefix str "VMDK" ||
+ String.is_prefix str "KDMV" ||
+ String.is_prefix str "# Disk DescriptorFile\n" then
+ error "input file is a VMDK (disk image), but we are expecting a \
+ VMX (VMware metadata)";
+
+ (* Split the input into lines. *)
let lines = String.nsplit "\n" str in
(* I've never seen any VMX file with CR-LF endings, and VMware