From patchwork Fri Dec 12 17:09:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 420589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1EDBC14009B for ; Sat, 13 Dec 2014 04:15:22 +1100 (AEDT) Received: from localhost ([::1]:58617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzToG-0005UP-7i for incoming@patchwork.ozlabs.org; Fri, 12 Dec 2014 12:15:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzTjQ-0005hj-Mw for qemu-devel@nongnu.org; Fri, 12 Dec 2014 12:10:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XzTjK-0004BS-HI for qemu-devel@nongnu.org; Fri, 12 Dec 2014 12:10:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45077) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzTjK-0004BO-8G for qemu-devel@nongnu.org; Fri, 12 Dec 2014 12:10:14 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBCHABZ3004136 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 12 Dec 2014 12:10:11 -0500 Received: from localhost (ovpn-112-32.ams2.redhat.com [10.36.112.32]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBCHAAkr032409; Fri, 12 Dec 2014 12:10:11 -0500 From: Stefan Hajnoczi To: Date: Fri, 12 Dec 2014 17:09:48 +0000 Message-Id: <1418404205-6213-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1418404205-6213-1-git-send-email-stefanha@redhat.com> References: <1418404205-6213-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PULL 02/19] vmdk: Fix error for JSON descriptor file names X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Max Reitz If vmdk blindly tries to use path_combine() using bs->file->filename as the base file name, this will result in a bad error message for JSON file names when calling bdrv_open(). It is better to only try bs->file->exact_filename; if that is empty, bs->file->filename will be useless for path_combine() and an error should be emitted (containing bs->file->filename because desc_file_path (which is bs->file->exact_filename) is empty). Signed-off-by: Max Reitz Reviewed-by: Fam Zheng Message-id: 1417615043-26174-2-git-send-email-mreitz@redhat.com Signed-off-by: Stefan Hajnoczi --- block.c | 2 +- block/vmdk.c | 10 +++++++++- include/block/block.h | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 82f33c5..a75a992 100644 --- a/block.c +++ b/block.c @@ -229,7 +229,7 @@ size_t bdrv_opt_mem_align(BlockDriverState *bs) } /* check if the path starts with ":" */ -static int path_has_protocol(const char *path) +int path_has_protocol(const char *path) { const char *p; diff --git a/block/vmdk.c b/block/vmdk.c index 65af414..bfff900 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -833,6 +833,14 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, goto next_line; } + if (!path_is_absolute(fname) && !path_has_protocol(fname) && + !desc_file_path[0]) + { + error_setg(errp, "Cannot use relative extent paths with VMDK " + "descriptor file '%s'", bs->file->filename); + return -EINVAL; + } + path_combine(extent_path, sizeof(extent_path), desc_file_path, fname); extent_file = NULL; @@ -909,7 +917,7 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf, } s->create_type = g_strdup(ct); s->desc_offset = 0; - ret = vmdk_parse_extents(buf, bs, bs->file->filename, errp); + ret = vmdk_parse_extents(buf, bs, bs->file->exact_filename, errp); exit: return ret; } diff --git a/include/block/block.h b/include/block/block.h index 610be9f..919c8f5 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -401,6 +401,7 @@ void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz); int bdrv_is_snapshot(BlockDriverState *bs); +int path_has_protocol(const char *path); int path_is_absolute(const char *path); void path_combine(char *dest, int dest_size, const char *base_path,