PR fortran/95088 - Buffer overflows with PDTs, submodules and long symbols

With PDTs (parameterized derived types) and submodules, name mangling
results in variably long internal symbols.  Instead of using a fixed-size
intermediate buffer, which is actually not really needed, just use a
pointer to strings.

2020-06-14  Harald Anlauf  <anlauf@gmx.de>

gcc/fortran/
	PR fortran/95088
	* class.c (get_unique_type_string): Replace use of fixed size
	buffer by internally passing a pointer to strings.
This commit is contained in:
Harald Anlauf 2020-06-14 16:12:47 +02:00
parent 4644e8f15f
commit 3ee9d82484
2 changed files with 34 additions and 11 deletions

View File

@ -479,19 +479,11 @@ gfc_class_initializer (gfc_typespec *ts, gfc_expr *init_expr)
static void
get_unique_type_string (char *string, gfc_symbol *derived)
{
/* Provide sufficient space to hold "Pdtsymbol". */
char dt_name[GFC_MAX_SYMBOL_LEN+4];
const char *dt_name;
if (derived->attr.unlimited_polymorphic)
strcpy (dt_name, "STAR");
dt_name = "STAR";
else
{
const char *upper = gfc_dt_upper_string (derived->name);
size_t len = strnlen (upper, sizeof (dt_name));
if (len >= sizeof (dt_name))
gfc_internal_error ("get_unique_type_string: identifier overflow");
memcpy (dt_name, upper, len);
dt_name[len] = '\0';
}
dt_name = gfc_dt_upper_string (derived->name);
if (derived->attr.unlimited_polymorphic)
sprintf (string, "_%s", dt_name);
else if (derived->module)

View File

@ -0,0 +1,31 @@
! { dg-do compile }
! { dg-options "-fsecond-underscore" }
! PR fortran/95088 - ICE in gfc_build_class_symbol, at fortran/class.c:653
module m2345678901234567890123456789012345678901234567890123456789_123
type t2345678901234567890123456789012345678901234567890123456789_123 &
(n2345678901234567890123456789012345678901234567890123456789_123,&
r2345678901234567890123456789012345678901234567890123456789_123,&
k2345678901234567890123456789012345678901234567890123456789_123,&
l2345678901234567890123456789012345678901234567890123456789_123 )
integer, kind :: n2345678901234567890123456789012345678901234567890123456789_123
integer, kind :: r2345678901234567890123456789012345678901234567890123456789_123
integer, kind :: k2345678901234567890123456789012345678901234567890123456789_123
integer, len :: l2345678901234567890123456789012345678901234567890123456789_123
complex (kind = r2345678901234567890123456789012345678901234567890123456789_123) &
:: z2345678901234567890123456789012345678901234567890123456789_123
character(kind = k2345678901234567890123456789012345678901234567890123456789_123, &
len = l2345678901234567890123456789012345678901234567890123456789_123) &
:: c2345678901234567890123456789012345678901234567890123456789_123
end type
type, extends (t2345678901234567890123456789012345678901234567890123456789_123) :: &
a2345678901234567890123456789012345678901234567890123456789_123
end type
interface
module subroutine s2345678901234567890123456789012345678901234567890123456789_123 &
(x2345678901234567890123456789012345678901234567890123456789_123)
class(a2345678901234567890123456789012345678901234567890123456789_123(16,8,4,1234567890)) :: &
x2345678901234567890123456789012345678901234567890123456789_123
end
end interface
end