]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR fortran/96381 - invalid read in gfc_find_derived_vtab
authorHarald Anlauf <anlauf@gmx.de>
Fri, 1 Jan 2021 17:55:41 +0000 (18:55 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Mon, 4 Jan 2021 20:56:15 +0000 (21:56 +0100)
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.

(cherry picked from commit d816b0c144d15e6570eb5b124b9f3ccbe3d40082)

gcc/fortran/class.c

index dfa484007120307c43fe14e48d3e4bdf32fe03fd..f017fbe3be7d2c536bb7921a4e5619edb81dd3d1 100644 (file)
@@ -2904,7 +2904,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;