diff mbox

fortran/67526 -- fix NULL pointer issue

Message ID 20150909232707.GA31830@troutmask.apl.washington.edu
State New
Headers show

Commit Message

Steve Kargl Sept. 9, 2015, 11:27 p.m. UTC
The attached patch fixes a NULL pointer dereference.  When
gfortran runs into an incomplete substring in an initialization
expression, she dereferences a NULL pointer.  The patch checks
for NULL and returns false, which allows gfortran to issue a
sensible error message.  Regression tested on x86_64-*-freebsd.
OK to commit?

2015-09-09  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/67526
	* gfortran.dg/pr67526.f90: New test.

2015-09-09  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/67526
	* expr.c (gfc_check_init_expr): Do not dereference a NULL pointer.

Comments

FX Coudert Sept. 10, 2015, 6:10 a.m. UTC | #1
> 2015-09-09  Steven G. Kargl  <kargl@gcc.gnu.org>
> 
> 	PR fortran/67526
> 	* gfortran.dg/pr67526.f90: New test.
> 
> 2015-09-09  Steven G. Kargl  <kargl@gcc.gnu.org>
> 
> 	PR fortran/67526
> 	* expr.c (gfc_check_init_expr): Do not dereference a NULL pointer.

OK.
Thanks for the patch!
diff mbox

Patch

Index: testsuite/gfortran.dg/pr67526.f90
===================================================================
--- testsuite/gfortran.dg/pr67526.f90	(revision 0)
+++ testsuite/gfortran.dg/pr67526.f90	(working copy)
@@ -0,0 +1,9 @@ 
+! { dg-do compile }
+! Original code from gerhard dot steinmetz dot fortran at t-online dot de
+! PR fortran/67526
+program p
+   character :: c1 = 'abc'(:     ! { dg-error "error in SUBSTRING" }
+   character :: c2 = 'abc'(3:    ! { dg-error "error in SUBSTRING" }
+   character :: c3 = 'abc'(:1    ! { dg-error "error in SUBSTRING" }
+   character :: c4 = 'abc'(2:2   ! { dg-error "error in SUBSTRING" }
+end
Index: fortran/expr.c
===================================================================
--- fortran/expr.c	(revision 227600)
+++ fortran/expr.c	(working copy)
@@ -2600,14 +2604,18 @@  gfc_check_init_expr (gfc_expr *e)
       break;
 
     case EXPR_SUBSTRING:
-      t = gfc_check_init_expr (e->ref->u.ss.start);
-      if (!t)
-	break;
-
-      t = gfc_check_init_expr (e->ref->u.ss.end);
-      if (t)
-	t = gfc_simplify_expr (e, 0);
+      if (e->ref)
+	{
+	  t = gfc_check_init_expr (e->ref->u.ss.start);
+	  if (!t)
+	    break;
 
+	  t = gfc_check_init_expr (e->ref->u.ss.end);
+	  if (t)
+	    t = gfc_simplify_expr (e, 0);
+	}
+      else
+	t = false;
       break;
 
     case EXPR_STRUCTURE: