[Pkg-libvirt-commits] [libguestfs] 164/384: mllib: add simple qemu filename sanitizing function
Hilko Bengen
bengen at moszumanska.debian.org
Sun Mar 29 16:56:46 UTC 2015
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch experimental
in repository libguestfs.
commit c796280a8ee45c223a184b956423c55e3af68d81
Author: Pino Toscano <ptoscano at redhat.com>
Date: Fri Jan 16 19:19:16 2015 +0100
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 a18490e..39b5653 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 16036b7..5661cab 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. *)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list