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 r11-10503] Fortran: fix NULL pointer dereference in gfc_check_dependency [PR108502]
Date: Sat,  4 Feb 2023 15:43:22 +0000 (GMT)	[thread overview]
Message-ID: <20230204154322.30C44385800A@sourceware.org> (raw)

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

commit r11-10503-gd7ec0bdfeae883d852d7c0dfc67766a3793f5892
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Jan 23 22:13:44 2023 +0100

    Fortran: fix NULL pointer dereference in gfc_check_dependency [PR108502]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/108502
            * dependency.c (gfc_check_dependency): Prevent NULL pointer
            dereference while recursively checking expressions.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/108502
            * gfortran.dg/pr108502.f90: New test.
    
    (cherry picked from commit 51767f31878a95161142254dca7119b409699670)

Diff:
---
 gcc/fortran/dependency.c               |  5 +++++
 gcc/testsuite/gfortran.dg/pr108502.f90 | 12 ++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/gcc/fortran/dependency.c b/gcc/fortran/dependency.c
index e1336e1c654..7a3cc82a5b2 100644
--- a/gcc/fortran/dependency.c
+++ b/gcc/fortran/dependency.c
@@ -1292,6 +1292,11 @@ gfc_check_dependency (gfc_expr *expr1, gfc_expr *expr2, bool identical)
   if (expr1->expr_type != EXPR_VARIABLE)
     gfc_internal_error ("gfc_check_dependency: expecting an EXPR_VARIABLE");
 
+  /* Prevent NULL pointer dereference while recursively analyzing invalid
+     expressions.  */
+  if (expr2 == NULL)
+    return 0;
+
   switch (expr2->expr_type)
     {
     case EXPR_OP:
diff --git a/gcc/testsuite/gfortran.dg/pr108502.f90 b/gcc/testsuite/gfortran.dg/pr108502.f90
new file mode 100644
index 00000000000..45f73849c57
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr108502.f90
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! { dg-options "-O2 -ffrontend-optimize" }
+! PR fortran/108502 - ICE in gfc_check_dependency
+! Contributed by G.Steinmetz
+
+integer function n()
+  integer :: a(1)
+  a = [1] / 0
+end
+program p
+  integer :: b = n() ! { dg-error "must be an intrinsic function" }
+end

                 reply	other threads:[~2023-02-04 15:43 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=20230204154322.30C44385800A@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).