This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [Patch, Fortran] Prevent segfault on illegal input
- From: Andre Vehreschild <vehre at gmx dot de>
- To: Tobias Burnus <tobias dot burnus at physik dot fu-berlin dot de>
- Cc: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Mon, 16 Mar 2015 11:32:10 +0100
- Subject: Re: [Patch, Fortran] Prevent segfault on illegal input
- Authentication-results: sourceware.org; auth=none
- References: <20150313113336 dot 154f327b at vepi2> <20150313130459 dot GA4148 at physik dot fu-berlin dot de>
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
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.