diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-04-12 17:07:49 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-04-12 18:59:14 +0100 |
commit | d2183a62aadff11609b561d3f821ec7d6094aa39 (patch) | |
tree | 28c21fffd98d5d8f0785bda2abbf8887021cb2b8 | |
parent | 4be630edb31f654068509d470e8b44039580954d (diff) | |
download | libguestfs-d2183a62aadff11609b561d3f821ec7d6094aa39.tar.gz libguestfs-d2183a62aadff11609b561d3f821ec7d6094aa39.tar.xz libguestfs-d2183a62aadff11609b561d3f821ec7d6094aa39.zip |
lib: Escape , as ,, on qemu command line (RHBZ#811649).
-rw-r--r-- | src/launch.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/launch.c b/src/launch.c index fe858b8d..b61c538a 100644 --- a/src/launch.c +++ b/src/launch.c @@ -1370,18 +1370,31 @@ is_openable (guestfs_h *g, const char *path, int flags) static char * qemu_drive_param (guestfs_h *g, const struct drive *drv) { + size_t i; size_t len = 64; + const char *p; char *r; - len += strlen (drv->path); + len += strlen (drv->path) * 2; /* every "," could become ",," */ len += strlen (drv->iface); if (drv->format) len += strlen (drv->format); r = safe_malloc (g, len); - snprintf (r, len, "file=%s%s%s%s%s,if=%s", - drv->path, + strcpy (r, "file="); + i = 5; + + /* Copy the path in, escaping any "," as ",,". */ + for (p = drv->path; *p; p++) { + if (*p == ',') { + r[i++] = ','; + r[i++] = ','; + } else + r[i++] = *p; + } + + snprintf (&r[i], len-i, "%s%s%s%s,if=%s", drv->readonly ? ",snapshot=on" : "", drv->use_cache_off ? ",cache=off" : "", drv->format ? ",format=" : "", |