From: Harald Anlauf Date: Thu, 25 Jun 2020 18:34:48 +0000 (+0200) Subject: PR fortran/95828 - Buffer overflows with SELECT RANK X-Git-Tag: upstream/12.2.0~15287 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=77d455ee81ec3a23f8b20259a31ab963716f8e82;p=platform%2Fupstream%2Fgcc.git PR fortran/95828 - Buffer overflows with SELECT RANK With SELECT RANK, name mangling results in long internal symbols that overflows internal buffers. Fix that. gcc/fortran/ PR fortran/95828 * match.c (select_rank_set_tmp): Enlarge internal buffer used in generating a mangled name. * resolve.c (resolve_select_rank): Likewise. --- diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 8063fca..b011634 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -6496,7 +6496,7 @@ static void select_rank_set_tmp (gfc_typespec *ts, int *case_value) { char name[2 * GFC_MAX_SYMBOL_LEN]; - char tname[GFC_MAX_SYMBOL_LEN]; + char tname[GFC_MAX_SYMBOL_LEN + 7]; gfc_symtree *tmp; gfc_symbol *selector = select_type_stack->selector; gfc_symbol *sym; diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 8c602da..6fa34ca 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -9635,7 +9635,7 @@ resolve_select_rank (gfc_code *code, gfc_namespace *old_ns) gfc_namespace *ns; gfc_code *body, *new_st, *tail; gfc_case *c; - char tname[GFC_MAX_SYMBOL_LEN]; + char tname[GFC_MAX_SYMBOL_LEN + 7]; char name[2 * GFC_MAX_SYMBOL_LEN]; gfc_symtree *st; gfc_expr *selector_expr = NULL; diff --git a/gcc/testsuite/gfortran.dg/pr95828.f90 b/gcc/testsuite/gfortran.dg/pr95828.f90 new file mode 100644 index 0000000..e85b2f1 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr95828.f90 @@ -0,0 +1,21 @@ +! { dg-do compile } +! { dg-options "-fsecond-underscore" } +! PR fortran/95828 - ICE in resolve_select_rank, at fortran/resolve.c:9774 + +module m2345678901234567890123456789012345678901234567890123456789_123 + type t2345678901234567890123456789012345678901234567890123456789_123 + end type +contains + subroutine s2345678901234567890123456789012345678901234567890123456789_123 & + (x2345678901234567890123456789012345678901234567890123456789_123) + type (t2345678901234567890123456789012345678901234567890123456789_123) :: & + x2345678901234567890123456789012345678901234567890123456789_123(..) + + select rank (y2345678901234567890123456789012345678901234567890123456789_123 & + => x2345678901234567890123456789012345678901234567890123456789_123) + rank (2) + rank (3) + rank default + end select + end +end