]> 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>
Wed, 10 Nov 2021 19:30:27 +0000 (20:30 +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.

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

index 15772009af47f662b392b1da51d11d78ae018e7f..ffa07b510cd81946a465b64f3a2dda7bfec4b55a 100644 (file)
@@ -5096,6 +5096,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 d675f2c3aeff4ad1128ef32c215055effff12cdd..6a6b3fbd0375918020a887c92730a02af231bc85 100644 (file)
@@ -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);
@@ -8174,6 +8177,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;