aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2020-06-07 14:47:24 +0200
committerHarald Anlauf <anlauf@gmx.de>2020-06-07 14:47:24 +0200
commitb342cfd648e6658363c7c8fef83af8f59dba1795 (patch)
tree9a1a25ff8675055eead33666adabad390ffe3fe4 /gcc/fortran
parentd8930b138788258aaad77b8fe821ce44d08a66d1 (diff)
downloadgcc-b342cfd648e6658363c7c8fef83af8f59dba1795.zip
gcc-b342cfd648e6658363c7c8fef83af8f59dba1795.tar.gz
gcc-b342cfd648e6658363c7c8fef83af8f59dba1795.tar.bz2
PR fortran/95091 - Buffer overflows with submodules and long symbols
With submodules, name mangling results in long internal symbols. This requires adjustment of the sizes of temporaries to avoid buffer overflows. 2020-06-07 Harald Anlauf <anlauf@gmx.de> gcc/fortran/ PR fortran/95091 * class.c (get_unique_type_string, gfc_hash_value): Enlarge buffers, and check whether the strings returned by get_unique_type_string() fit.
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/class.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c
index b176407..8bb7350 100644
--- a/gcc/fortran/class.c
+++ b/gcc/fortran/class.c
@@ -509,9 +509,11 @@ get_unique_type_string (char *string, gfc_symbol *derived)
static void
get_unique_hashed_string (char *string, gfc_symbol *derived)
{
- /* Provide sufficient space to hold "symbol_Pdtsymbol". */
- char tmp[2*GFC_MAX_SYMBOL_LEN+5];
+ /* Provide sufficient space to hold "symbol.symbol_symbol". */
+ char tmp[3*GFC_MAX_SYMBOL_LEN+3];
get_unique_type_string (&tmp[0], derived);
+ size_t len = strnlen (tmp, sizeof (tmp));
+ gcc_assert (len < sizeof (tmp));
/* If string is too long, use hash value in hex representation (allow for
extra decoration, cf. gfc_build_class_symbol & gfc_find_derived_vtab).
We need space to for 15 characters "__class_" + symbol name + "_%d_%da",
@@ -532,12 +534,13 @@ unsigned int
gfc_hash_value (gfc_symbol *sym)
{
unsigned int hash = 0;
- /* Provide sufficient space to hold "symbol_Pdtsymbol". */
- char c[2*GFC_MAX_SYMBOL_LEN+5];
+ /* Provide sufficient space to hold "symbol.symbol_symbol". */
+ char c[3*GFC_MAX_SYMBOL_LEN+3];
int i, len;
get_unique_type_string (&c[0], sym);
- len = strlen (c);
+ len = strnlen (c, sizeof (c));
+ gcc_assert (len < sizeof (c));
for (i = 0; i < len; i++)
hash = (hash << 6) + (hash << 16) - hash + c[i];