https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95689

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
                 CC|                            |anlauf at gcc dot gnu.org
     Ever confirmed|0                           |1
           Priority|P3                          |P4
            Summary|ICE in                      |[8/9/10/11 Regression] ICE
                   |check_sym_interfaces, at    |in check_sym_interfaces, at
                   |fortran/interface.c:2015    |fortran/interface.c:2015
           Assignee|unassigned at gcc dot gnu.org      |anlauf at gcc dot 
gnu.org

--- Comment #2 from anlauf at gcc dot gnu.org ---
Technically an 8/9/10/11 regression.

The following patch fixes the ICE for me:

diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index f33c6632b45..b1a75a37b0e 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -1981,7 +1981,8 @@ check_interface1 (gfc_interface *p, gfc_interface *q0,
 static void
 check_sym_interfaces (gfc_symbol *sym)
 {
-  char interface_name[GFC_MAX_SYMBOL_LEN + sizeof("generic interface ''")];
+  /* Provide sufficient space to hold "generic interface 'symbol.symbol'".  */
+  char interface_name[2*GFC_MAX_SYMBOL_LEN+2 + sizeof("generic interface
''")];
   gfc_interface *p;

   if (sym->ns != gfc_current_ns)
@@ -1989,6 +1990,8 @@ check_sym_interfaces (gfc_symbol *sym)

   if (sym->generic != NULL)
     {
+      size_t len = strlen (sym->name) + sizeof("generic interface ''");
+      gcc_assert (len < sizeof (interface_name));
       sprintf (interface_name, "generic interface '%s'", sym->name);
       if (check_interface0 (sym->generic, interface_name))
        return;

Not regtested yet.  The testcase may show subsequent fallout elsewhere
(i.e. for builds with special protection against buffer overflows).

Reply via email to