From 85421c7c712ea16c05f782348f62314c8709c2e9 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sat, 20 Jun 2020 16:15:16 +0200 Subject: PR fortran/95707 - ICE in finish_equivalences, at fortran/trans-common.c:1319 With submodules and equivalence declarations, name mangling may result in long internal symbols overflowing internal buffers. We now check that we do not exceed the enlarged buffer sizes. gcc/fortran/ PR fortran/95707 * gfortran.h (gfc_common_head): Enlarge buffer. * trans-common.c (gfc_sym_mangled_common_id): Enlarge temporary buffers, and add check on length on mangled name to prevent overflow. --- gcc/fortran/trans-common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'gcc/fortran/trans-common.c') diff --git a/gcc/fortran/trans-common.c b/gcc/fortran/trans-common.c index 1acc336..c6383fc 100644 --- a/gcc/fortran/trans-common.c +++ b/gcc/fortran/trans-common.c @@ -242,11 +242,13 @@ static tree gfc_sym_mangled_common_id (gfc_common_head *com) { int has_underscore; - /* Provide sufficient space to hold "symbol.eq.1234567890__". */ - char mangled_name[GFC_MAX_MANGLED_SYMBOL_LEN + 1 + 16]; - char name[GFC_MAX_SYMBOL_LEN + 1 + 16]; + /* Provide sufficient space to hold "symbol.symbol.eq.1234567890__". */ + char mangled_name[2*GFC_MAX_MANGLED_SYMBOL_LEN + 1 + 16 + 1]; + char name[sizeof (mangled_name) - 2]; /* Get the name out of the common block pointer. */ + size_t len = strlen (com->name); + gcc_assert (len < sizeof (name)); strcpy (name, com->name); /* If we're suppose to do a bind(c). */ -- cgit v1.1