From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eduard - Gabriel Munteanu Subject: [RFC PATCH 1/7] acpi: qemu_realloc() might return a different pointer Date: Tue, 30 Mar 2010 11:20:02 +0300 Message-ID: <9b87085a250d0f70509687e4ab09336244734fad.1269936879.git.eduard.munteanu@linux360.ro> References: Cc: aliguori@us.ibm.com, avi@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, Eduard - Gabriel Munteanu To: joro@8bytes.org Return-path: Received: from mail-bw0-f209.google.com ([209.85.218.209]:41750 "EHLO mail-bw0-f209.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755599Ab0C3IU0 (ORCPT ); Tue, 30 Mar 2010 04:20:26 -0400 Received: by bwz1 with SMTP id 1so4153668bwz.21 for ; Tue, 30 Mar 2010 01:20:24 -0700 (PDT) In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: 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; -- 1.6.4.4 From mboxrd@z Thu Jan 1 00:00:00 1970 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) Sender: Eduard - Gabriel Munteanu From: Eduard - Gabriel Munteanu Date: Tue, 30 Mar 2010 11:20:02 +0300 Message-Id: <9b87085a250d0f70509687e4ab09336244734fad.1269936879.git.eduard.munteanu@linux360.ro> In-Reply-To: References: Subject: [Qemu-devel] [RFC PATCH 1/7] acpi: qemu_realloc() might return a different pointer List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: joro@8bytes.org Cc: aliguori@us.ibm.com, Eduard - Gabriel Munteanu , avi@redhat.com, kvm@vger.kernel.org, qemu-devel@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; -- 1.6.4.4