[Pkg-libvirt-commits] [libguestfs] 114/146: mllib: add simple qemu filename sanitizing function

Hilko Bengen bengen at moszumanska.debian.org
Sun Mar 29 17:01:14 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch master
in repository libguestfs.

commit c921f3d1bd7f076ee04b40e6196374931eebe693
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. ':'.
    
    (cherry picked from commit c796280a8ee45c223a184b956423c55e3af68d81)
---
 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 7c64ad0..eb7997a 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -593,3 +593,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 6d0a0fc..b6fe273 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -129,3 +129,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