]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: avoid NULL pointer dereferences
authorHarald Anlauf <anlauf@gmx.de>
Wed, 10 Nov 2021 19:30:27 +0000 (20:30 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Sat, 13 Nov 2021 20:00:17 +0000 (21:00 +0100)
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)

gcc/fortran/check.c
gcc/fortran/simplify.c

index 5ecfea077a150bfec5121b03b0c24f1d750711ee..f37016bced54c7f98f32f40718c4e9de66de7ffa 100644 (file)
@@ -5085,6 +5085,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)
index 48a109c14812d251105ff51b0b7bf3a91d6faf14..0e5c383f9bda773e724ac62e5a841e8cafbb2edf 100644 (file)
@@ -2077,6 +2077,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);
@@ -8076,6 +8079,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;