diff options
author | Harald Anlauf <anlauf@gmx.de> | 2020-06-25 20:32:13 +0200 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2020-06-25 20:32:13 +0200 |
commit | 35a335a159216548fc77263ac5df71ff29d3f448 (patch) | |
tree | 70460bb97d27ffe4ab264f6024bb0e4ff402c6c1 /gcc/fortran/decl.c | |
parent | 20f466326ca08d7dac58eb34ffdd6bf80428c5ab (diff) | |
download | gcc-35a335a159216548fc77263ac5df71ff29d3f448.zip gcc-35a335a159216548fc77263ac5df71ff29d3f448.tar.gz gcc-35a335a159216548fc77263ac5df71ff29d3f448.tar.bz2 |
PR fortran/95826 - Buffer overflows with PDTs and long symbols
With PDTs (parameterized derived types), name mangling results in variably
long internal symbols. Use a dynamic buffer instead of a fixed-size one.
gcc/fortran/
PR fortran/95826
* decl.c (gfc_match_decl_type_spec): Replace a fixed size
buffer by a pointer and reallocate if necessary.
Diffstat (limited to 'gcc/fortran/decl.c')
-rw-r--r-- | gcc/fortran/decl.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index c27cfac..ac1f63f 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -4095,7 +4095,7 @@ match gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag) { /* Provide sufficient space to hold "pdtsymbol". */ - char name[GFC_MAX_SYMBOL_LEN + 1 + 3]; + char *name = XALLOCAVEC (char, GFC_MAX_SYMBOL_LEN + 1); gfc_symbol *sym, *dt_sym; match m; char c; @@ -4286,8 +4286,10 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag) gcc_assert (!sym->attr.pdt_template && sym->attr.pdt_type); ts->u.derived = sym; const char* lower = gfc_dt_lower_string (sym->name); - size_t len = strnlen (lower, sizeof (name)); - gcc_assert (len < sizeof (name)); + size_t len = strlen (lower); + /* Reallocate with sufficient size. */ + if (len > GFC_MAX_SYMBOL_LEN) + name = XALLOCAVEC (char, len + 1); memcpy (name, lower, len); name[len] = '\0'; } |