This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] fortran/67526 -- fix NULL pointer issue
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Wed, 9 Sep 2015 16:27:07 -0700
- Subject: [PATCH] fortran/67526 -- fix NULL pointer issue
- Authentication-results: sourceware.org; auth=none
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.
--
Steve
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: