From d136595df77f75bc6e5132e26f09cad031f38c71 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 24 Oct 2019 10:49:02 +0200 Subject: [PATCH] Fix another UBSAN in Fortran coarray. 2019-10-24 Martin Liska PR fortran/92174 * array.c (gfc_resolve_array_spec): Break the loop for out of bounds index. * resolve.c (is_non_constant_shape_array): Likewise. From-SVN: r277367 --- gcc/fortran/ChangeLog | 7 +++++++ gcc/fortran/array.c | 3 +++ gcc/fortran/resolve.c | 3 +++ 3 files changed, 13 insertions(+) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 5bb04d779eb..4e3910298b6 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2019-10-24 Martin Liska + + PR fortran/92174 + * array.c (gfc_resolve_array_spec): Break the loop + for out of bounds index. + * resolve.c (is_non_constant_shape_array): Likewise. + 2019-10-23 Steven G. Kargl dump-parse-tree.c (show_expr): Add dumping of BT_BOZ constants. diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index f0980dd9cef..36223d2233d 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -410,6 +410,9 @@ gfc_resolve_array_spec (gfc_array_spec *as, int check_constant) for (i = 0; i < as->rank + as->corank; i++) { + if (i == GFC_MAX_DIMENSIONS) + return false; + e = as->lower[i]; if (!resolve_array_bound (e, check_constant)) return false; diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 93f2d0aa761..5deeb4fc87b 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -12266,6 +12266,9 @@ is_non_constant_shape_array (gfc_symbol *sym) simplification now. */ for (i = 0; i < sym->as->rank + sym->as->corank; i++) { + if (i == GFC_MAX_DIMENSIONS) + break; + e = sym->as->lower[i]; if (e && (!resolve_index_expr(e) || !gfc_is_constant_expr (e))) -- 2.30.2