public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran] Prevent segfault on illegal input
@ 2015-03-13 10:33 Andre Vehreschild
  2015-03-13 13:05 ` Tobias Burnus
  0 siblings, 1 reply; 3+ messages in thread
From: Andre Vehreschild @ 2015-03-13 10:33 UTC (permalink / raw)
  To: GCC-Patches-ML, GCC-Fortran-ML

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

Hi all,

during debugging I found a segfault of gfortran, when it encounters an illegal
fortran code. The mistake in Fortran is flagged correctly, but later gfortran
crashes. This patch prevents the crash.

Bootstraps and regtest ok on x86_64-linux-gnu.

Ok for trunk?

Regards,
	Andre
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: crashfix1_v1.clog --]
[-- Type: application/octet-stream, Size: 236 bytes --]

gcc/fortran/ChangeLog:

2015-03-13  Andre Vehreschild  <vehre@gmx.de>

	* resolve.c: Prevent segfault on illegal input.

gcc/testsuite/ChangeLog:

2015-03-13  Andre Vehreschild  <vehre@gmx.de>

	* gfortran.dg/pointer_2.f90: New test.



[-- Attachment #3: crashfix1_v1.patch --]
[-- Type: text/x-patch, Size: 1288 bytes --]

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 942a9ad..465cf2b 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -2639,6 +2639,10 @@ found:
     expr->ts = sym->ts;
   expr->value.function.name = sym->name;
   expr->value.function.esym = sym;
+  /* Prevent crash when sym->ts.u.derived->components is not set due to previous
+     error(s).  */
+  if (sym->ts.type == BT_CLASS && !CLASS_DATA (sym))
+    return MATCH_ERROR;
   if (sym->ts.type == BT_CLASS && CLASS_DATA (sym)->as)
     expr->rank = CLASS_DATA (sym)->as->rank;
   else if (sym->as != NULL)
diff --git a/gcc/testsuite/gfortran.dg/pointer_2.f90 b/gcc/testsuite/gfortran.dg/pointer_2.f90
new file mode 100644
index 0000000..d3b95d6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pointer_2.f90
@@ -0,0 +1,18 @@
+! { dg-do compile }
+! Check that the compiler reports the errors, but does not segfault.
+! Contributed by: Andre Vehreschild  <vehre@gcc.gnu.org>
+!
+program test
+    implicit none
+    class(*), pointer :: P
+    class(*), allocatable :: P2
+
+    allocate(P2, source=convertType(P))
+
+contains
+
+  function convertType(in) ! { dg-error "must be dummy, allocatable or pointer" }
+    class(*), intent(in) :: in
+    class(*) :: convertType
+  end function
+end program test

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch, Fortran] Prevent segfault on illegal input
  2015-03-13 10:33 [Patch, Fortran] Prevent segfault on illegal input Andre Vehreschild
@ 2015-03-13 13:05 ` Tobias Burnus
  2015-03-16 10:32   ` Andre Vehreschild
  0 siblings, 1 reply; 3+ messages in thread
From: Tobias Burnus @ 2015-03-13 13:05 UTC (permalink / raw)
  To: Andre Vehreschild, gcc-patches, fortran

Andre Vehreschild wrote:
> during debugging I found a segfault of gfortran, when it encounters an illegal
> fortran code. The mistake in Fortran is flagged correctly, but later gfortran
> crashes. This patch prevents the crash.
>
> Bootstraps and regtest ok on x86_64-linux-gnu.
> Ok for trunk?

OK. Thanks for the patch.

Tobias

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch, Fortran] Prevent segfault on illegal input
  2015-03-13 13:05 ` Tobias Burnus
@ 2015-03-16 10:32   ` Andre Vehreschild
  0 siblings, 0 replies; 3+ messages in thread
From: Andre Vehreschild @ 2015-03-16 10:32 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, fortran

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

Hi Tobias, hi all,

thanks for the review. Commited as r221455:

r221455 | vehre | 2015-03-16 11:29:59 +0100 (Mo, 16. Mär 2015) | 13 Zeilen

gcc/fortran/ChangeLog:

2015-03-16  Andre Vehreschild  <vehre@gmx.de>

	* resolve.c: Prevent segfault on illegal input.

gcc/testsuite/ChangeLog:

2015-03-16  Andre Vehreschild  <vehre@gmx.de>

	* gfortran.dg/pointer_2.f90: New test.

Regards,
	Andre

On Fri, 13 Mar 2015 14:05:00 +0100
Tobias Burnus <tobias.burnus@physik.fu-berlin.de> wrote:

> Andre Vehreschild wrote:
> > during debugging I found a segfault of gfortran, when it encounters an
> > illegal fortran code. The mistake in Fortran is flagged correctly, but
> > later gfortran crashes. This patch prevents the crash.
> >
> > Bootstraps and regtest ok on x86_64-linux-gnu.
> > Ok for trunk?
> 
> OK. Thanks for the patch.
> 
> Tobias


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: crashfix1.patch --]
[-- Type: text/x-patch, Size: 2113 bytes --]

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 221454)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,7 @@
+2015-03-16  Andre Vehreschild  <vehre@gmx.de>
+
+	* resolve.c: Prevent segfault on illegal input.
+
 2015-03-14  Mikael Morin  <mikael@gcc.gnu.org>
 
 	PR fortran/61138
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(Revision 221454)
+++ gcc/fortran/resolve.c	(Arbeitskopie)
@@ -2639,6 +2639,10 @@
     expr->ts = sym->ts;
   expr->value.function.name = sym->name;
   expr->value.function.esym = sym;
+  /* Prevent crash when sym->ts.u.derived->components is not set due to previous
+     error(s).  */
+  if (sym->ts.type == BT_CLASS && !CLASS_DATA (sym))
+    return MATCH_ERROR;
   if (sym->ts.type == BT_CLASS && CLASS_DATA (sym)->as)
     expr->rank = CLASS_DATA (sym)->as->rank;
   else if (sym->as != NULL)
Index: gcc/testsuite/gfortran.dg/pointer_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pointer_2.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/pointer_2.f90	(Revision 221455)
@@ -0,0 +1,18 @@
+! { dg-do compile }
+! Check that the compiler reports the errors, but does not segfault.
+! Contributed by: Andre Vehreschild  <vehre@gcc.gnu.org>
+!
+program test
+    implicit none
+    class(*), pointer :: P
+    class(*), allocatable :: P2
+
+    allocate(P2, source=convertType(P))
+
+contains
+
+  function convertType(in) ! { dg-error "must be dummy, allocatable or pointer" }
+    class(*), intent(in) :: in
+    class(*) :: convertType
+  end function
+end program test
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 221454)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,7 @@
+2015-03-16  Andre Vehreschild  <vehre@gmx.de>
+
+	* gfortran.dg/pointer_2.f90: New test.
+
 2015-03-16  Eric Botcazou  <ebotcazou@adacore.com>
 
 	* testsuite/g++.dg/pr65049.C: New test.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-16 10:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-13 10:33 [Patch, Fortran] Prevent segfault on illegal input Andre Vehreschild
2015-03-13 13:05 ` Tobias Burnus
2015-03-16 10:32   ` Andre Vehreschild

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).