public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9235] Fortran: avoid NULL pointer dereferences
@ 2021-11-11 20:17 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2021-11-11 20:17 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9ccc4f79f1a6dd08437e10db729694a744abb10a

commit r11-9235-g9ccc4f79f1a6dd08437e10db729694a744abb10a
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Wed Nov 10 20:30:27 2021 +0100

    Fortran: avoid NULL pointer dereferences
    
    CLASS(), PARAMETER is not yet properly implemented in gfortran.  Using it
    in declarations could lead to subsequent NULL pointer dereferences during
    checking or simplification of expressions involving those CLASS variables.
    
    gcc/fortran/ChangeLog:
    
            PR fortran/103137
            PR fortran/103138
            * check.c (gfc_check_shape): Avoid NULL pointer dereference on
            missing ref.
            * simplify.c (gfc_simplify_cshift): Avoid NULL pointer dereference
            when shape not set.
            (gfc_simplify_transpose): Likewise.
    
    (cherry picked from commit abc2f01914d6c4703de26c402fb579a9a2d0dba4)

Diff:
---
 gcc/fortran/check.c    | 3 +++
 gcc/fortran/simplify.c | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 06acb80e3ac..e97b13838fb 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -5092,6 +5092,9 @@ gfc_check_shape (gfc_expr *source, gfc_expr *kind)
   if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
     return true;
 
+  if (source->ref == NULL)
+    return false;
+
   ar = gfc_find_array_ref (source);
 
   if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index f40e4930b58..4ee211f22ef 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -2109,6 +2109,9 @@ gfc_simplify_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
   else
     which = 0;
 
+  if (array->shape == NULL)
+    return NULL;
+
   gfc_array_size (array, &size);
   arraysize = mpz_get_ui (size);
   mpz_clear (size);
@@ -8168,6 +8171,9 @@ gfc_simplify_transpose (gfc_expr *matrix)
 
   gcc_assert (matrix->rank == 2);
 
+  if (matrix->shape == NULL)
+    return NULL;
+
   result = gfc_get_array_expr (matrix->ts.type, matrix->ts.kind,
 			       &matrix->where);
   result->rank = 2;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-11 20:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-11 20:17 [gcc r11-9235] Fortran: avoid NULL pointer dereferences Harald Anlauf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).