From patchwork Wed Apr 20 17:33:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 66229 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2581892qge; Wed, 20 Apr 2016 10:35:57 -0700 (PDT) X-Received: by 10.28.232.140 with SMTP id f12mr10586847wmi.6.1461173754864; Wed, 20 Apr 2016 10:35:54 -0700 (PDT) Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com. [209.132.183.25]) by mx.google.com with ESMTPS id d62si11134546wme.62.2016.04.20.10.35.54 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Apr 2016 10:35:54 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u3KHXJiQ010719; Wed, 20 Apr 2016 13:33:20 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u3KHXIpV020826 for ; Wed, 20 Apr 2016 13:33:18 -0400 Received: from colepc.redhat.com (ovpn-113-99.phx2.redhat.com [10.3.113.99]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3KHXH4D013954; Wed, 20 Apr 2016 13:33:18 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Wed, 20 Apr 2016 13:33:15 -0400 Message-Id: <579d698a22ccd7c07ad2c9990f86d5efd2fee014.1461173595.git.crobinso@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virsh: blockcopy: force an absolute path X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com 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 --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);