From patchwork Tue Mar 30 08:20:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard - Gabriel Munteanu X-Patchwork-Id: 48969 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 82978B7C7E for ; Wed, 31 Mar 2010 01:30:09 +1100 (EST) Received: from localhost ([127.0.0.1]:38495 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NwcRF-0000Ku-Cy for incoming@patchwork.ozlabs.org; Tue, 30 Mar 2010 10:29:05 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NwWgf-0003Ng-Cj for qemu-devel@nongnu.org; Tue, 30 Mar 2010 04:20:37 -0400 Received: from [140.186.70.92] (port=40376 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NwWgb-0003LZ-J7 for qemu-devel@nongnu.org; Tue, 30 Mar 2010 04:20:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NwWgV-00048g-Um for qemu-devel@nongnu.org; Tue, 30 Mar 2010 04:20:33 -0400 Received: from mail-bw0-f218.google.com ([209.85.218.218]:62851) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NwWgT-00048C-LZ for qemu-devel@nongnu.org; Tue, 30 Mar 2010 04:20:25 -0400 Received: by bwz10 with SMTP id 10so14273957bwz.2 for ; Tue, 30 Mar 2010 01:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:cc:subject :date:message-id:x-mailer:in-reply-to:references; bh=lKmY5m17++iYsWi2NyQS1DGs0iFrEwtoNvrzkq8+WIM=; b=FqSSl5P8aURBEPCN6aoiJFRCILEzETp1oqFXRufRi7qHuQpN8pKkg3ATvp7V4PHNyq GRQ3THZF9yp+3CzS84wn3u2wYYHZ8mOeyFBAbQ6kzWKHXXQPZsJm6MyeSVhF1jm1QQvz 8c6kR9NrCYd6Zhe6UEt85AUqVmkBhBLXFbt+k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=KMpBdd0DXv32TN+xKrVdYFovpbiixUnytWWokOXjt2DU2SoL2I1UrWVTfioBsJrTrH gFIJD2hH5yWyPtXi9EYbK483cDZEqiZ2UG8DlIsaFrFm1fIYbtzkCAmz58kGMllWaZTT KXpNiTod0LJx35gndWHtEmiAtgdnxmvtgeWQw= Received: by 10.204.140.212 with SMTP id j20mr634590bku.119.1269937223978; Tue, 30 Mar 2010 01:20:23 -0700 (PDT) Received: from localhost.localdomain ([188.25.93.130]) by mx.google.com with ESMTPS id 16sm2589620bwz.9.2010.03.30.01.20.22 (version=SSLv3 cipher=RC4-MD5); Tue, 30 Mar 2010 01:20:23 -0700 (PDT) From: Eduard - Gabriel Munteanu To: joro@8bytes.org Date: Tue, 30 Mar 2010 11:20:02 +0300 Message-Id: <9b87085a250d0f70509687e4ab09336244734fad.1269936879.git.eduard.munteanu@linux360.ro> X-Mailer: git-send-email 1.6.4.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Mailman-Approved-At: Tue, 30 Mar 2010 10:20:52 -0400 Cc: aliguori@us.ibm.com, Eduard - Gabriel Munteanu , avi@redhat.com, kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [Qemu-devel] [RFC PATCH 1/7] acpi: qemu_realloc() might return a different pointer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We mustn't assume qemu_realloc() returns the same pointer in acpi_table_add(). Therefore, 'p' might be invalid if it's relative to the old value of acpi_tables. Signed-off-by: Eduard - Gabriel Munteanu --- hw/acpi.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/acpi.c b/hw/acpi.c index d293127..7c4e8d3 100644 --- a/hw/acpi.c +++ b/hw/acpi.c @@ -857,7 +857,7 @@ int acpi_table_add(const char *t) char buf[1024], *p, *f; struct acpi_table_header acpi_hdr; unsigned long val; - size_t off; + size_t newlen, off; memset(&acpi_hdr, 0, sizeof(acpi_hdr)); @@ -938,9 +938,10 @@ int acpi_table_add(const char *t) acpi_tables_len = sizeof(uint16_t); acpi_tables = qemu_mallocz(acpi_tables_len); } + newlen = acpi_tables_len + sizeof(uint16_t) + acpi_hdr.length; + acpi_tables = qemu_realloc(acpi_tables, newlen); p = acpi_tables + acpi_tables_len; - acpi_tables_len += sizeof(uint16_t) + acpi_hdr.length; - acpi_tables = qemu_realloc(acpi_tables, acpi_tables_len); + acpi_tables_len = newlen; acpi_hdr.length = cpu_to_le32(acpi_hdr.length); *(uint16_t*)p = acpi_hdr.length;