[Libguestfs] [PATCH] v2v: -i vmx: Refuse to load a disk image by accident.

Richard W.M. Jones rjones at redhat.com
Wed Oct 11 13:25:26 UTC 2017


If you accidentally point -i vmx at a disk image, it will try to load
the whole thing into memory and crash.  Catch this narrow case and
print an error.

However don't fail if ‘file’ is not installed or if we don't know what
the file is.
---
 v2v/parse_vmx.ml | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/v2v/parse_vmx.ml b/v2v/parse_vmx.ml
index 65d5a0edd..f6c34e2cf 100644
--- a/v2v/parse_vmx.ml
+++ b/v2v/parse_vmx.ml
@@ -268,6 +268,18 @@ let remove_vmx_escapes str =
 
 (* Parsing. *)
 let rec parse_file vmx_filename =
+  (* One person pointed -i vmx at the VMDK file, resulting in an out
+   * of memory error.  Avoid this narrow case.
+   *)
+  let () =
+    let cmd = sprintf "file -b %s ||:" (quote vmx_filename) in
+    let out = external_command cmd in
+    match out with
+    | line :: _ when String.find line "disk image" >= 0 ->
+       error (f_"-i vmx: %s: this may be a disk image.  You must specify the .vmx file only on the command line.")
+             vmx_filename
+    | _ -> () in
+
   (* Read the whole file as a list of lines. *)
   let str = read_whole_file vmx_filename in
   if verbose () then eprintf "VMX file:\n%s\n" str;
-- 
2.13.2




More information about the Libguestfs mailing list