From patchwork Wed Mar 28 12:52:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 149227 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0C8B5B6EF1 for ; Thu, 29 Mar 2012 01:26:42 +1100 (EST) Received: from localhost ([::1]:42797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCsOP-0008I9-Pt for incoming@patchwork.ozlabs.org; Wed, 28 Mar 2012 08:54:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40046) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCsN1-0005XO-95 for qemu-devel@nongnu.org; Wed, 28 Mar 2012 08:53:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCsMs-0007v4-5P for qemu-devel@nongnu.org; Wed, 28 Mar 2012 08:52:58 -0400 Received: from cantor2.suse.de ([195.135.220.15]:39617 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCsMr-0007pf-NQ; Wed, 28 Mar 2012 08:52:49 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 5F33290983; Wed, 28 Mar 2012 14:52:47 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Wed, 28 Mar 2012 14:52:32 +0200 Message-Id: <1332939159-16434-30-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1332939159-16434-1-git-send-email-afaerber@suse.de> References: <1332939159-16434-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Kevin Wolf , kvm@suse.de, qemu-stable@nongnu.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= , Bruce Rogers Subject: [Qemu-devel] [PATCH stable-0.15 29/36] vmdk: Fix possible segfaults 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: Kevin Wolf Data we read from the disk isn't necessarily null terminated and may not contain the string we're looking for. The code needs to be a bit more careful here. Signed-off-by: Kevin Wolf (cherry picked from commit 93897b9fd43548e9c15cf8bece2d9e5174b01fc7) Signed-off-by: Bruce Rogers Signed-off-by: Andreas Färber --- block/vmdk.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 8284747..f4fce08 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -196,6 +196,7 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent) cid_str_size = sizeof("CID"); } + desc[DESC_SIZE - 1] = '\0'; p_name = strstr(desc, cid_str); if (p_name != NULL) { p_name += cid_str_size; @@ -212,13 +213,17 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid) BDRVVmdkState *s = bs->opaque; int ret; - memset(desc, 0, sizeof(desc)); ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE); if (ret < 0) { return ret; } + desc[DESC_SIZE - 1] = '\0'; tmp_str = strstr(desc, "parentCID"); + if (tmp_str == NULL) { + return -EINVAL; + } + pstrcpy(tmp_desc, sizeof(tmp_desc), tmp_str); p_name = strstr(desc, "CID"); if (p_name != NULL) {