From: Alex Coplan <alex.coplan@arm.com>
To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com
Subject: Re: [PATCH] varasm: Fix type confusion bug
Date: Thu, 1 Dec 2022 17:59:17 +0000 [thread overview]
Message-ID: <Y4jrdfzlhnw7tEzA@arm.com> (raw)
In-Reply-To: <mpta6473xye.fsf@arm.com>
On 01/12/2022 16:12, Richard Sandiford wrote:
> Alex Coplan via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> > Hi,
> >
> > 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.
> >
> > Bootstrapped/regtested on aarch64-none-linux-gnu, OK for trunk?
>
> OK, thanks. I think it's OK for backports too if you like,
> since it's a regression from around 2013.
Thanks, I've pushed the patch to trunk, and will backport if there are
no complaints after a week or so.
Alex
>
> Richard
>
> >
> > Thanks,
> > Alex
> >
> > gcc/ChangeLog:
> >
> > * varasm.cc (assemble_variable): Fix type confusion bug when
> > checking for ".vtable_map_vars" section.
> >
> > 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
prev parent reply other threads:[~2022-12-01 17:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-01 15:33 Alex Coplan
2022-12-01 16:12 ` Richard Sandiford
2022-12-01 17:59 ` Alex Coplan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y4jrdfzlhnw7tEzA@arm.com \
--to=alex.coplan@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=richard.sandiford@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).