From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHYed-0000UJ-Id for qemu-devel@nongnu.org; Fri, 08 Jan 2016 10:08:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aHYec-0001w3-4O for qemu-devel@nongnu.org; Fri, 08 Jan 2016 10:08:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52399) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHYeb-0001vy-V8 for qemu-devel@nongnu.org; Fri, 08 Jan 2016 10:08:38 -0500 Date: Fri, 8 Jan 2016 17:08:34 +0200 From: "Michael S. Tsirkin" Message-ID: <1452262668-31244-2-git-send-email-mst@redhat.com> References: <1452262668-31244-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1452262668-31244-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL 01/59] nvdimm: fix header pointer in nvdimm_build_nfit() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Igor Mammedov , Xiao Guangrong , Haozhong Zhang From: Haozhong Zhang In the current nvdimm_build_nfit(), the pointer 'header' initially equals to table_data->data + table_data->len. However, the following g_array_append_vals(table_data, structures->data, structures->len) may resize and relocate table_data->data[]. Therefore, the usage of 'header' afterwards may be illegal. This patch fixes this issue by storing an offset within table_data->data[] (rather than an address) in 'header'. Signed-off-by: Haozhong Zhang Reviewed-by: Xiao Guangrong Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/acpi/nvdimm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 9534418..df1b176 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -353,16 +353,18 @@ static void nvdimm_build_nfit(GSList *device_list, GArray *table_offsets, GArray *table_data, GArray *linker) { GArray *structures = nvdimm_build_device_structure(device_list); - void *header; + unsigned int header; acpi_add_table(table_offsets, table_data); /* NFIT header. */ - header = acpi_data_push(table_data, sizeof(NvdimmNfitHeader)); + header = table_data->len; + acpi_data_push(table_data, sizeof(NvdimmNfitHeader)); /* NVDIMM device structures. */ g_array_append_vals(table_data, structures->data, structures->len); - build_header(linker, table_data, header, "NFIT", + build_header(linker, table_data, + (void *)(table_data->data + header), "NFIT", sizeof(NvdimmNfitHeader) + structures->len, 1, NULL); g_array_free(structures, true); } -- MST