public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-4451] varasm: Fix type confusion bug
@ 2022-12-01 17:36 Alex Coplan
  0 siblings, 0 replies; only message in thread
From: Alex Coplan @ 2022-12-01 17:36 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:de144fdab17dbbb64ccb540056ab78b4ffb3fbbc

commit r13-4451-gde144fdab17dbbb64ccb540056ab78b4ffb3fbbc
Author: Alex Coplan <alex.coplan@arm.com>
Date:   Thu Dec 1 17:36:02 2022 +0000

    varasm: Fix type confusion bug
    
    This patch fixes a type confusion bug in varasm.cc: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.cc (assemble_variable): Fix type confusion bug when
            checking for ".vtable_map_vars" section.

Diff:
---
 gcc/varasm.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 9dfbebbb915..6851201b6a2 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -2400,7 +2400,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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-01 17:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-01 17:36 [gcc r13-4451] varasm: Fix type confusion bug Alex Coplan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).