Pino Toscano
2015-Jan-16 18:33 UTC
[Libguestfs] [PATCH 1/2] mllib: add simple qemu filename sanitizing function
It mimics a bit in OCaml the logic used in commit a95214b1985e694946e3426120a6fdc13a3f081f (for the main library) and commit 588af1953e5f7ab74009b9175cc5d3efb8bb651a (in disk-create), so in OCaml tools direct calls to qemu/qemu-img with filenames provided by the user can properly handle filenames with e.g. ':'. --- mllib/common_utils.ml | 13 +++++++++++++ mllib/common_utils.mli | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml index b143710..4d3bf95 100644 --- a/mllib/common_utils.ml +++ b/mllib/common_utils.ml @@ -603,3 +603,16 @@ let is_directory path let absolute_path path if not (Filename.is_relative path) then path else Sys.getcwd () // path + +(* Sanitizes a filename for passing it safely to qemu/qemu-img. + * + * If the filename is something like "file:foo" then qemu-img will + * try to interpret that as "foo" in the file:/// protocol. To + * avoid that, if the path is relative prefix it with "./" since + * qemu-img won't try to interpret such a path. + *) +let qemu_input_filename filename + if String.length filename > 0 && filename.[0] <> '/' then + "./" ^ filename + else + filename diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli index 2103ff1..e59d802 100644 --- a/mllib/common_utils.mli +++ b/mllib/common_utils.mli @@ -131,3 +131,11 @@ val is_directory : string -> bool val absolute_path : string -> string (** Convert any path to an absolute path. *) + +val qemu_input_filename : string -> string +(** Sanitizes a filename for passing it safely to qemu/qemu-img. + + If the filename is something like "file:foo" then qemu-img will + try to interpret that as "foo" in the file:/// protocol. To + avoid that, if the path is relative prefix it with "./" since + qemu-img won't try to interpret such a path. *) -- 1.9.3
Pino Toscano
2015-Jan-16 18:33 UTC
[Libguestfs] [PATCH 2/2] sparsify: handle output filenames with ':'
With commit a594b7f90a682e2a9327b142138edb76ad8ba8ff the checks for input and output files with ':' were removed; while the input file is handled correctly by the disk_create API, an output filename with ':' could still be handled as specifying a transport, failing the last "qemu-img convert" call. Use the new qemu_input_filename helper to handle the output filename correctly. --- sparsify/copying.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sparsify/copying.ml b/sparsify/copying.ml index 3628b01..d4861f9 100644 --- a/sparsify/copying.ml +++ b/sparsify/copying.ml @@ -311,7 +311,7 @@ You can ignore this warning or change it to a hard failure using the (match option with | None -> "" | Some option -> " -o " ^ quote option) - (quote overlaydisk) (quote outdisk) in + (quote overlaydisk) (quote (qemu_input_filename outdisk)) in if verbose then printf "%s\n%!" cmd; if Sys.command cmd <> 0 then -- 1.9.3
Richard W.M. Jones
2015-Jan-19 14:45 UTC
Re: [Libguestfs] [PATCH 2/2] sparsify: handle output filenames with ':'
On Fri, Jan 16, 2015 at 07:33:20PM +0100, Pino Toscano wrote:> With commit a594b7f90a682e2a9327b142138edb76ad8ba8ff the checks for > input and output files with ':' were removed; while the input file is > handled correctly by the disk_create API, an output filename with ':' > could still be handled as specifying a transport, failing the last > "qemu-img convert" call. > > Use the new qemu_input_filename helper to handle the output filename > correctly. > --- > sparsify/copying.ml | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/sparsify/copying.ml b/sparsify/copying.ml > index 3628b01..d4861f9 100644 > --- a/sparsify/copying.ml > +++ b/sparsify/copying.ml > @@ -311,7 +311,7 @@ You can ignore this warning or change it to a hard failure using the > (match option with > | None -> "" > | Some option -> " -o " ^ quote option) > - (quote overlaydisk) (quote outdisk) in > + (quote overlaydisk) (quote (qemu_input_filename outdisk)) in > if verbose then > printf "%s\n%!" cmd; > if Sys.command cmd <> 0 thenACK both. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Maybe Matching Threads
- [PATCH 1/2] mllib: add simple qemu filename sanitizing function
- [PATCH] OCaml tools: use open_guestfs everywhere
- [PATCH 1/2] sparsify: Refactor handling of checks of copying mode / --in-place.
- [PATCH] sparsify: Make the interface between cmdline.ml and sparsify.ml explicit.
- [PATCH] sparsify, v2v: use Common_utils.absolute_path