public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/96381 - invalid read in gfc_find_derived_vtab
@ 2021-01-01 16:14 Harald Anlauf
  2021-01-01 17:07 ` Paul Richard Thomas
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2021-01-01 16:14 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1184 bytes --]

Dear all,

happy New Year!

The testcase committed with the fix for PR93337 uncovered a latent issue
with an invalid read that was discovered with an ASAN instrumented compiler
but which could also be verified by running f951 under valgrind.

According to my gdb sessions the invalid read happens when processing a
statement that refers to a rejected declaration of a CLASS instance.
We simply should not try to look up the vtab entry in such cases.

All variations of the testcase gfortran.dg/pr93337.f90 that I tried on
x86_64-pc-linux-gnu with the patch below appeared to behave clean running
f951 under valgrind.

Regtested on x86_64-pc-linux-gnu.

OK for master?  Since the fix for PR93337 was applied to 9/10/11, I intend
to backport after suitable waiting time.

Thanks,
Harald


PR fortran/96381 - invalid read in gfc_find_derived_vtab

An invalid declaration of a CLASS instance can lead to an internal state
with inconsistent attributes during parsing that needs to be handled with
sufficient care when processing subsequent statements.  Avoid a lookup of
the vtab entry for such cases.

gcc/fortran/ChangeLog:

	* class.c (gfc_find_vtab): Add check on attribute is_class.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr96381.patch --]
[-- Type: text/x-patch, Size: 598 bytes --]

diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c
index 5677d920239..783e4c7354b 100644
--- a/gcc/fortran/class.c
+++ b/gcc/fortran/class.c
@@ -2906,7 +2906,9 @@ gfc_find_vtab (gfc_typespec *ts)
     case BT_DERIVED:
       return gfc_find_derived_vtab (ts->u.derived);
     case BT_CLASS:
-      if (ts->u.derived->components && ts->u.derived->components->ts.u.derived)
+      if (ts->u.derived->attr.is_class
+	  && ts->u.derived->components
+	  && ts->u.derived->components->ts.u.derived)
 	return gfc_find_derived_vtab (ts->u.derived->components->ts.u.derived);
       else
 	return NULL;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] PR fortran/96381 - invalid read in gfc_find_derived_vtab
  2021-01-01 16:14 [PATCH] PR fortran/96381 - invalid read in gfc_find_derived_vtab Harald Anlauf
@ 2021-01-01 17:07 ` Paul Richard Thomas
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Richard Thomas @ 2021-01-01 17:07 UTC (permalink / raw)
  To: Harald Anlauf; +Cc: fortran, gcc-patches

Hi Harald,

It looks good to me - OK for master and backporting.

Thanks

Paul


On Fri, 1 Jan 2021 at 16:14, Harald Anlauf via Fortran <fortran@gcc.gnu.org>
wrote:

> Dear all,
>
> happy New Year!
>
> The testcase committed with the fix for PR93337 uncovered a latent issue
> with an invalid read that was discovered with an ASAN instrumented compiler
> but which could also be verified by running f951 under valgrind.
>
> According to my gdb sessions the invalid read happens when processing a
> statement that refers to a rejected declaration of a CLASS instance.
> We simply should not try to look up the vtab entry in such cases.
>
> All variations of the testcase gfortran.dg/pr93337.f90 that I tried on
> x86_64-pc-linux-gnu with the patch below appeared to behave clean running
> f951 under valgrind.
>
> Regtested on x86_64-pc-linux-gnu.
>
> OK for master?  Since the fix for PR93337 was applied to 9/10/11, I intend
> to backport after suitable waiting time.
>
> Thanks,
> Harald
>
>
> PR fortran/96381 - invalid read in gfc_find_derived_vtab
>
> An invalid declaration of a CLASS instance can lead to an internal state
> with inconsistent attributes during parsing that needs to be handled with
> sufficient care when processing subsequent statements.  Avoid a lookup of
> the vtab entry for such cases.
>
> gcc/fortran/ChangeLog:
>
>         * class.c (gfc_find_vtab): Add check on attribute is_class.
>
>

-- 
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-01 17:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-01 16:14 [PATCH] PR fortran/96381 - invalid read in gfc_find_derived_vtab Harald Anlauf
2021-01-01 17:07 ` Paul Richard Thomas

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).