diff mbox

virsh: blockcopy: force an absolute path

Message ID 579d698a22ccd7c07ad2c9990f86d5efd2fee014.1461173595.git.crobinso@redhat.com
State New
Headers show

Commit Message

Cole Robinson April 20, 2016, 5:33 p.m. UTC
virsh doesn't reject or absolutify a passed relative path, which
can give unexpected results. Convert a relative path to an absolute
one before calling the API

https://bugzilla.redhat.com/show_bug.cgi?id=1300177
---
 tools/virsh-domain.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

-- 
2.7.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox

Patch

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index a1d4a75..7074ded 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2256,8 +2256,9 @@  static bool
 cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom = NULL;
-    const char *dest = NULL;
+    const char *dest_cli = NULL;
     const char *format = NULL;
+    char *dest = NULL;
     unsigned long bandwidth = 0;
     unsigned int granularity = 0;
     unsigned long long buf_size = 0;
@@ -2281,7 +2282,7 @@  cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
 
     if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
         return false;
-    if (vshCommandOptStringReq(ctl, cmd, "dest", &dest) < 0)
+    if (vshCommandOptStringReq(ctl, cmd, "dest", &dest_cli) < 0)
         return false;
     if (vshCommandOptStringReq(ctl, cmd, "xml", &xml) < 0)
         return false;
@@ -2308,6 +2309,11 @@  cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
     if (async)
         abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC;
 
+    if (dest_cli && virFileAbsPath(dest_cli, &dest) < 0) {
+        vshError(ctl, _("failed to build absolute path for %s"), dest_cli);
+        return false;
+    }
+
     VSH_EXCLUSIVE_OPTIONS_VAR(dest, xml);
     VSH_EXCLUSIVE_OPTIONS_VAR(format, xml);
     VSH_EXCLUSIVE_OPTIONS_VAR(blockdev, xml);
@@ -2462,6 +2468,7 @@  cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
     ret = true;
 
  cleanup:
+    VIR_FREE(dest);
     VIR_FREE(xmlstr);
     virTypedParamsFree(params, nparams);
     virDomainFree(dom);