From nobody Thu May 2 22:06:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490694072477374.83496917428124; Tue, 28 Mar 2017 02:41:12 -0700 (PDT) Received: from localhost ([::1]:51971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csnck-00032V-O0 for importer@patchew.org; Tue, 28 Mar 2017 05:41:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53452) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csnc1-0002gj-71 for qemu-devel@nongnu.org; Tue, 28 Mar 2017 05:40:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csnc0-0000JK-9j for qemu-devel@nongnu.org; Tue, 28 Mar 2017 05:40:25 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48952) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1csnc0-0000Ii-20 for qemu-devel@nongnu.org; Tue, 28 Mar 2017 05:40:24 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1csnbv-0001Ed-Gl; Tue, 28 Mar 2017 10:40:19 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 28 Mar 2017 10:40:17 +0100 Message-Id: <1490694017-7532-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH for-2.9 v2] tests/bios-tables-test: Don't pass addresses of packed struct fields X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Igor Mammedov , "Michael S. Tsirkin" , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Passing the address of a field in a packed struct to a function that expects a pointer to normally aligned data will result in a SEGBUS on architectures like SPARC that have strict alignment requirements. Pass addresses of local variables rather than addresses of packed structure fields to glib functions like g_file_get_contents() to avoid this bug. Signed-off-by: Peter Maydell Reviewed-by: Eric Blake Reviewed-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- v1->v2 changes: put the assignments after we check the error status of the glib function, rather than before (makes no practical difference since we will just assert out anyway, but logically the right way round.) tests/bios-tables-test.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 88dbf97..a519921 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -261,8 +261,11 @@ static void dump_aml_files(test_data *data, bool rebui= ld) fd =3D g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); } else { - fd =3D g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error); + gchar *name; + + fd =3D g_file_open_tmp("aml-XXXXXX", &name, &error); g_assert_no_error(error); + sdt->aml_file =3D name; } g_assert(fd >=3D 0); =20 @@ -291,9 +294,11 @@ static bool load_asl(GArray *sdts, AcpiSdtTable *sdt) gchar *out, *out_err; gboolean ret; int i; + gchar *name; =20 - fd =3D g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error); + fd =3D g_file_open_tmp("asl-XXXXXX.dsl", &name, &error); g_assert_no_error(error); + sdt->asl_file =3D name; close(fd); =20 /* build command line */ @@ -314,10 +319,14 @@ static bool load_asl(GArray *sdts, AcpiSdtTable *sdt) ret =3D g_spawn_command_line_sync(command_line->str, &out, &out_err, N= ULL, &error); g_assert_no_error(error); if (ret) { - ret =3D g_file_get_contents(sdt->asl_file, (gchar **)&sdt->asl, - &sdt->asl_len, &error); + gchar *contents; + gsize len; + + ret =3D g_file_get_contents(sdt->asl_file, &contents, &len, &error= ); g_assert(ret); g_assert_no_error(error); + sdt->asl =3D contents; + sdt->asl_len =3D len; ret =3D (sdt->asl_len > 0); } =20 @@ -371,6 +380,8 @@ static GArray *load_expected_aml(test_data *data) uint32_t signature; gchar *aml_file =3D NULL; const char *ext =3D data->variant ? data->variant : ""; + gchar *aml_contents; + gsize aml_length; =20 sdt =3D &g_array_index(data->tables, AcpiSdtTable, i); =20 @@ -397,12 +408,13 @@ try_again: if (getenv("V")) { fprintf(stderr, "\nUsing expected file '%s'\n", aml_file); } - ret =3D g_file_get_contents(aml_file, &exp_sdt.aml, - &exp_sdt.aml_len, &error); + ret =3D g_file_get_contents(aml_file, &aml_contents, &aml_length, = &error); g_assert(ret); g_assert_no_error(error); - g_assert(exp_sdt.aml); - g_assert(exp_sdt.aml_len); + g_assert(aml_contents); + g_assert(aml_length); + exp_sdt.aml =3D aml_contents; + exp_sdt.aml_len =3D aml_length; =20 g_array_append_val(exp_tables, exp_sdt); } --=20 2.7.4