From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7810) id A8D3C3858CDB; Mon, 16 Jan 2023 13:15:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8D3C3858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673874909; bh=NMUo54lec0otT3i3lpqdUi6u10UYYo9ddDsRx6vWYfQ=; h=From:To:Subject:Date:From; b=FEtWRNz1mpsqynUd34ckhhaapu2lINY3oAPGH7tryDl2rqfWQCjZO3jjdNxqlTX4I Go/2eYNTlORtgJXqg7t+y+hQ1izlzWRgS+yeWO1dgjYGHzAuoZOOjrhqd0K4+RoW/O Ps0zbJ0MhjKAUzfggt1SuCUHldX5bICvKOIEMtEQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Alex Coplan To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10469] varasm: Fix type confusion bug X-Act-Checkin: gcc X-Git-Author: Alex Coplan X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 2b7df1c2baee87203836b7e6540d5f1d283a9edf X-Git-Newrev: 260297e42ca9eddf31aae4acb8a214d3f96a4b16 Message-Id: <20230116131509.A8D3C3858CDB@sourceware.org> Date: Mon, 16 Jan 2023 13:15:09 +0000 (GMT) List-Id: https://gcc.gnu.org/g:260297e42ca9eddf31aae4acb8a214d3f96a4b16 commit r11-10469-g260297e42ca9eddf31aae4acb8a214d3f96a4b16 Author: Alex Coplan Date: Thu Dec 1 17:36:02 2022 +0000 varasm: Fix type confusion bug This patch fixes a type confusion bug in varasm.c:assemble_variable. The problem is that the current code calls: sect = get_variable_section (decl, false); and then accesses sect->named.name without checking whether the section is in fact a named section. In the surrounding else clause, we only know that SECTION_STYLE (sect) != SECTION_NOSWITCH, so it is possible that the section is an unnamed section. In practice, this means that we end up doing a wild string compare between a function pointer and the string literal ".vtable_map_vars". This is because sect->named.name aliases sect->unnamed.callback in the section union. This can be seen in GDB with a simple testcase such as "int x;". This patch fixes the issue by checking the SECTION_STYLE of the section is in fact SECTION_NAMED before trying to do the string comparison. We drop the existing check of whether sect->named.name is non-NULL because this should presumably always be the case for a named section. gcc/ChangeLog: * varasm.c (assemble_variable): Fix type confusion bug when checking for ".vtable_map_vars" section. (cherry picked from commit de144fdab17dbbb64ccb540056ab78b4ffb3fbbc) Diff: --- gcc/varasm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/varasm.c b/gcc/varasm.c index 93b9c8ef0ee..8e456576010 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -2380,7 +2380,7 @@ assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED, else { /* Special-case handling of vtv comdat sections. */ - if (sect->named.name + if (SECTION_STYLE (sect) == SECTION_NAMED && (strcmp (sect->named.name, ".vtable_map_vars") == 0)) handle_vtv_comdat_section (sect, decl); else