From patchwork Wed Mar 23 03:33:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 601099 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qVFbc5fX7z9srh for ; Wed, 23 Mar 2016 14:36:28 +1100 (AEDT) Received: from localhost ([::1]:40756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiZas-0002sb-VX for incoming@patchwork.ozlabs.org; Tue, 22 Mar 2016 23:36:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiZYc-0006jP-4G for qemu-devel@nongnu.org; Tue, 22 Mar 2016 23:34:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aiZYb-0003cP-Bd for qemu-devel@nongnu.org; Tue, 22 Mar 2016 23:34:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36855) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiZYV-0003bG-NS; Tue, 22 Mar 2016 23:33:59 -0400 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 (Postfix) with ESMTPS id 5DAA850F55; Wed, 23 Mar 2016 03:33:59 +0000 (UTC) Received: from localhost (ovpn-112-65.phx2.redhat.com [10.3.112.65]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2N3XvOu021858 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA256 bits=256 verify=NO); Tue, 22 Mar 2016 23:33:58 -0400 From: Jeff Cody To: qemu-block@nongnu.org Date: Tue, 22 Mar 2016 23:33:43 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: 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: kwolf@redhat.com, grantwwu@gmail.com, qemu-devel@nongnu.org, stefanha@redhat.com, sbaugh@catern.com Subject: [Qemu-devel] [PATCH for-2.6 6/7] block/vpc: set errp in vpc_open 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 Add more useful error information to failure paths in vpc_open Signed-off-by: Jeff Cody --- block/vpc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block/vpc.c b/block/vpc.c index 67ab376..5dd9950 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -237,6 +237,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, ret = bdrv_pread(bs->file->bs, 0, s->footer_buf, HEADER_SIZE); if (ret < 0) { + error_setg(errp, "Unable to read VHD header"); goto fail; } @@ -245,9 +246,11 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, int64_t offset = bdrv_getlength(bs->file->bs); if (offset < 0) { ret = offset; + error_setg(errp, "Invalid file size"); goto fail; } else if (offset < HEADER_SIZE) { ret = -EINVAL; + error_setg(errp, "File too small for a VHD header"); goto fail; } @@ -326,12 +329,14 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, ret = bdrv_pread(bs->file->bs, be64_to_cpu(footer->data_offset), buf, HEADER_SIZE); if (ret < 0) { + error_setg(errp, "Error reading dynamic VHD header"); goto fail; } dyndisk_header = (VHDDynDiskHeader *) buf; if (strncmp(dyndisk_header->magic, "cxsparse", 8)) { + error_setg(errp, "Invalid header magic"); ret = -EINVAL; goto fail; } @@ -347,12 +352,14 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, s->max_table_entries = be32_to_cpu(dyndisk_header->max_table_entries); if ((bs->total_sectors * 512) / s->block_size > 0xffffffffU) { + error_setg(errp, "Too many blocks"); ret = -EINVAL; goto fail; } computed_size = (uint64_t) s->max_table_entries * s->block_size; if (computed_size < bs->total_sectors * 512) { + error_setg(errp, "Page table too small"); ret = -EINVAL; goto fail; } @@ -369,6 +376,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, s->pagetable = qemu_try_blockalign(bs->file->bs, pagetable_size); if (s->pagetable == NULL) { + error_setg(errp, "Unable to allocate memory for page table"); ret = -ENOMEM; goto fail; } @@ -378,6 +386,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, ret = bdrv_pread(bs->file->bs, s->bat_offset, s->pagetable, pagetable_size); if (ret < 0) { + error_setg(errp, "Error reading pagetable"); goto fail; }