From patchwork Wed Jan 13 15:43:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 567017 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 5466314032F for ; Thu, 14 Jan 2016 02:51:36 +1100 (AEDT) Received: from localhost ([::1]:37757 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJNhu-0002di-99 for incoming@patchwork.ozlabs.org; Wed, 13 Jan 2016 10:51:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJNaV-0004F1-Ax for qemu-devel@nongnu.org; Wed, 13 Jan 2016 10:43:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJNaR-0001Bp-LT for qemu-devel@nongnu.org; Wed, 13 Jan 2016 10:43:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJNaR-0001BO-C8 for qemu-devel@nongnu.org; Wed, 13 Jan 2016 10:43:51 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 0371AC60E9 for ; Wed, 13 Jan 2016 15:43:51 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-28.phx2.redhat.com [10.3.113.28]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0DFhlKT015932 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 13 Jan 2016 10:43:50 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 191CA3004F99; Wed, 13 Jan 2016 16:43:42 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 13 Jan 2016 16:43:32 +0100 Message-Id: <1452699819-26608-35-git-send-email-armbru@redhat.com> In-Reply-To: <1452699819-26608-1-git-send-email-armbru@redhat.com> References: <1452699819-26608-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Fam Zheng Subject: [Qemu-devel] [PULL 34/41] vmdk: Clean up "Invalid extent lines" error message 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 vmdk_parse_extents() reports parse errors like this: error_setg(errp, "Invalid extent lines:\n%s", p); where p points to the beginning of the malformed line in the image descriptor. This results in a multi-line error message Invalid extent lines: Error messages should not have newlines embedded. Since the remaining text is not helpful, we can simply report: Invalid extent line: Cc: Fam Zheng Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <1450452927-8346-19-git-send-email-armbru@redhat.com> Reviewed-by: Fam Zheng --- block/vmdk.c | 20 +++++++++++++------- tests/qemu-iotests/059.out | 4 +--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 08fa3f3..2b5cb00 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -780,7 +780,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, char access[11]; char type[11]; char fname[512]; - const char *p; + const char *p, *np; int64_t sectors = 0; int64_t flat_offset; char *extent_path; @@ -805,19 +805,16 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, continue; } else if (!strcmp(type, "FLAT")) { if (matches != 5 || flat_offset < 0) { - error_setg(errp, "Invalid extent lines: \n%s", p); - return -EINVAL; + goto invalid; } } else if (!strcmp(type, "VMFS")) { if (matches == 4) { flat_offset = 0; } else { - error_setg(errp, "Invalid extent lines:\n%s", p); - return -EINVAL; + goto invalid; } } else if (matches != 4) { - error_setg(errp, "Invalid extent lines:\n%s", p); - return -EINVAL; + goto invalid; } if (sectors <= 0 || @@ -883,6 +880,15 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, extent->type = g_strdup(type); } return 0; + +invalid: + np = next_line(p); + assert(np != p); + if (np[-1] == '\n') { + np--; + } + error_setg(errp, "Invalid extent line: %.*s", (int)(np - p), p); + return -EINVAL; } static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf, diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out index d28df5b..9d506cb 100644 --- a/tests/qemu-iotests/059.out +++ b/tests/qemu-iotests/059.out @@ -2038,9 +2038,7 @@ Format specific information: format: FLAT === Testing malformed VMFS extent description line === -qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Invalid extent lines: -RW 12582912 VMFS "dummy.IMGFMT" 1 - +qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Invalid extent line: RW 12582912 VMFS "dummy.IMGFMT" 1 === Testing truncated sparse === Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400 subformat=monolithicSparse