public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH, committed] Fortran: avoid NULL pointer dereference on bad EQUIVALENCEs [PR107559]
Date: Wed, 9 Nov 2022 21:17:43 +0100	[thread overview]
Message-ID: <trinity-60fde88b-2e53-405e-b0d6-3cc97ef45980-1668025063811@3c-app-gmx-bap34> (raw)

[-- Attachment #1: Type: text/plain, Size: 284 bytes --]

Dear all,

I've committed an obvious patch for NULL pointer dereferences
that could occur when checking EQUIVALENCEs.  See also attached.

Testcase by Gerhard.

Regtested on x86_64-pc-linux-gnu.

Pushed: https://gcc.gnu.org/g:e505f7493bed1395d121d2f53137ec11706fa42e

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr107559.diff --]
[-- Type: text/x-patch, Size: 2193 bytes --]

From e505f7493bed1395d121d2f53137ec11706fa42e Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Wed, 9 Nov 2022 21:05:28 +0100
Subject: [PATCH] Fortran: avoid NULL pointer dereference on bad EQUIVALENCEs
 [PR107559]

gcc/fortran/ChangeLog:

	PR fortran/107559
	* resolve.cc (resolve_equivalence): Avoid NULL pointer dereference
	while emitting diagnostics for bad EQUIVALENCEs.

gcc/testsuite/ChangeLog:

	PR fortran/107559
	* gfortran.dg/pr107559.f90: New test.
---
 gcc/fortran/resolve.cc                 |  2 ++
 gcc/testsuite/gfortran.dg/pr107559.f90 | 11 +++++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/pr107559.f90

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 9202e2f10ad..5ff1cd070ac 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -17218,6 +17218,7 @@ resolve_equivalence (gfc_equiv *eq)
 	    "statement at %L with different type objects";
       if ((object ==2
 	   && last_eq_type == SEQ_MIXED
+	   && last_where
 	   && !gfc_notify_std (GFC_STD_GNU, msg, first_sym->name, last_where))
 	  || (eq_type == SEQ_MIXED
 	      && !gfc_notify_std (GFC_STD_GNU, msg, sym->name, &e->where)))
@@ -17227,6 +17228,7 @@ resolve_equivalence (gfc_equiv *eq)
 	    "statement at %L with objects of different type";
       if ((object ==2
 	   && last_eq_type == SEQ_NONDEFAULT
+	   && last_where
 	   && !gfc_notify_std (GFC_STD_GNU, msg, first_sym->name, last_where))
 	  || (eq_type == SEQ_NONDEFAULT
 	      && !gfc_notify_std (GFC_STD_GNU, msg, sym->name, &e->where)))
diff --git a/gcc/testsuite/gfortran.dg/pr107559.f90 b/gcc/testsuite/gfortran.dg/pr107559.f90
new file mode 100644
index 00000000000..714e236df50
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr107559.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! { dg-options "-std=f95" }
+! PR fortran/107559 - ICE in resolve_equivalence
+! Contributed by G.Steinmetz
+
+module m
+  implicit none
+  integer, protected :: a ! { dg-error "Fortran 2003: PROTECTED attribute" }
+  integer :: b
+  equivalence (a, b)      ! { dg-error "has no IMPLICIT type" }
+end
--
2.35.3


                 reply	other threads:[~2022-11-09 20:17 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=trinity-60fde88b-2e53-405e-b0d6-3cc97ef45980-1668025063811@3c-app-gmx-bap34 \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@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).