public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-5136] Fortran: avoid NULL pointer dereferences
Date: Wed, 10 Nov 2021 19:42:36 +0000 (GMT)	[thread overview]
Message-ID: <20211110194236.6E3A23858D35@sourceware.org> (raw)

https://gcc.gnu.org/g:abc2f01914d6c4703de26c402fb579a9a2d0dba4

commit r12-5136-gabc2f01914d6c4703de26c402fb579a9a2d0dba4
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.

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 15772009af4..ffa07b510cd 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -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)
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index d675f2c3aef..6a6b3fbd037 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);
@@ -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;


                 reply	other threads:[~2021-11-10 19:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211110194236.6E3A23858D35@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).