summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-04-17 14:54:48 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-04-17 14:58:40 +0100
commit8d3d5a52d2746af91f770608cce5f47462f33aba (patch)
tree65ac62066181cbb5c5049977fa04f008b07a67c6
parentfb401ebff837f9df7c06acb8467b2c03d5b8ced0 (diff)
downloadlibguestfs-8d3d5a52d2746af91f770608cce5f47462f33aba.tar.gz
libguestfs-8d3d5a52d2746af91f770608cce5f47462f33aba.tar.xz
libguestfs-8d3d5a52d2746af91f770608cce5f47462f33aba.zip
sparsify: Fix comma/colon and quoting in qemu-img command.
Colon characters are not allowed in qemu/qemu-img filenames. There's no way to quote them. Comma characters CAN be used. However they must be quoted (by doubling) when used in the '-o' option. Fix general quoting problems in the external command.
-rw-r--r--sparsify/sparsify.ml29
-rw-r--r--sparsify/utils.ml10
2 files changed, 27 insertions, 12 deletions
diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml
index a5f95c91..8d23b405 100644
--- a/sparsify/sparsify.ml
+++ b/sparsify/sparsify.ml
@@ -130,12 +130,15 @@ read the man page virt-sparsify(1).
else
Sys.getcwd () // indisk in
- (* Check indisk filename doesn't contain a comma (limitation of qemu-img). *)
- let contains_comma =
- try ignore (String.index indisk ','); true
- with Not_found -> false in
- if contains_comma then
- error "input filename '%s' contains a comma; qemu-img command line syntax prevents us from using such an image" indisk;
+ let contains_colon filename =
+ try ignore (String.index filename ':'); true with Not_found -> false in
+
+ (* Check filenames don't contain a colon (limitation of qemu-img). *)
+ if contains_colon indisk then
+ error "input filename '%s' contains a colon (':'); qemu-img command line syntax prevents us from using such an image" indisk;
+
+ if contains_colon outdisk then
+ error "output filename '%s' contains a colon (':'); qemu-img command line syntax prevents us from using such an image" outdisk;
indisk, outdisk, compress, convert,
debug_gc, format, ignores, machine_readable,
@@ -158,12 +161,14 @@ let overlaydisk =
(* Create it with the indisk as the backing file. *)
let cmd =
- sprintf "qemu-img create -f qcow2 -o backing_file=%s%s %s > /dev/null"
- (Filename.quote indisk)
- (match format with
- | None -> ""
- | Some fmt -> sprintf ",backing_fmt=%s" (Filename.quote fmt))
- (Filename.quote tmp) in
+ let backing_file_option =
+ sprintf "backing_file=%s%s"
+ (replace_str indisk "," ",,")
+ (match format with
+ | None -> ""
+ | Some fmt -> sprintf ",backing_fmt=%s" fmt) in
+ sprintf "qemu-img create -f qcow2 -o %s %s > /dev/null"
+ (Filename.quote backing_file_option) (Filename.quote tmp) in
if verbose then
printf "%s\n%!" cmd;
if Sys.command cmd <> 0 then
diff --git a/sparsify/utils.ml b/sparsify/utils.ml
index e34fe403..d2be12c8 100644
--- a/sparsify/utils.ml
+++ b/sparsify/utils.ml
@@ -76,6 +76,16 @@ let rec string_find s sub =
in
loop 0
+let rec replace_str s s1 s2 =
+ let len = String.length s in
+ let sublen = String.length s1 in
+ let i = string_find s s1 in
+ if i = -1 then s
+ else (
+ let s' = String.sub s 0 i in
+ let s'' = String.sub s (i+sublen) (len-i-sublen) in
+ s' ^ s2 ^ replace_str s'' s1 s2
+ )
let string_random8 =
let chars = "abcdefghijklmnopqrstuvwxyz0123456789" in
fun () ->